/// <summary> /// /// </summary> /// <param name="application"></param> /// <param name="automation"></param> /// <param name="func"></param> /// <param name="settings"></param> /// <returns></returns> public static Window WaitMainWindow( this Application application, AutomationBase automation, Func <FindBuilder, FindBuilder> func, RetrySettings settings) { Window?window = null; var element = Retry.Find(() => { window = application.GetMainWindow(automation, Retry.DefaultInterval); return(window == null ? null : func(window.BuildFind()).FirstOrDefault()); }, settings); window = window ?? throw new InvalidOperationException("Main window is null"); // Throws right exception if (element == null) { func(window.BuildFind()).First(); } return(window); }
public void SearchWithRetryTest() { using (var app = Application.Launch("notepad.exe")) { using (var automation = new UIA3Automation()) { var window = app.GetMainWindow(automation); Assert.That(window, Is.Not.Null); Assert.That(window.Title, Is.Not.Null); Task.Factory.StartNew(async() => { await Task.Delay(5000); ShowHelpScreen(); }); var dialogWindow = Retry.Find(() => window.FindFirstChild(cf => cf.ByControlType(ControlType.Window)), new RetrySettings { Timeout = TimeSpan.FromSeconds(6), Interval = TimeSpan.FromMilliseconds(500) } ); } } }
public InfoScreen OpenAndGetInfoScreen() { // Open the screen with shortcuts if (Tools.OperatingSystem.CurrentCulture.TwoLetterISOLanguageName == "de") { Keyboard.TypeSimultaneously(VirtualKeyShort.ALT, VirtualKeyShort.KEY_D); Keyboard.Type(VirtualKeyShort.KEY_I); } else { Keyboard.TypeSimultaneously(VirtualKeyShort.ALT, VirtualKeyShort.KEY_F); Keyboard.Type(VirtualKeyShort.KEY_T); } // Do a retry to wait for the window return(Retry.Find(() => FindFirstChild(cf => cf.ByControlType(ControlType.Window)), new RetrySettings { Timeout = TimeSpan.FromSeconds(5), IgnoreException = true, ThrowOnTimeout = true, TimeoutMessage = "Failed to find info screen" }) .As <InfoScreen>()); }
public static void ClickButtonInWindowByText(Window window, string text) { var button = (Button)Retry.Find(() => window.FindFirstDescendant(x => x.ByText(text).And(x.ByControlType(ControlType.Button))).AsButton(), new RetrySettings { Timeout = TimeSpan.FromSeconds(10), Interval = TimeSpan.FromMilliseconds(500) } ); button.WaitUntilClickable(TimeSpan.FromSeconds(5)) .WaitUntilEnabled(TimeSpan.FromSeconds(5)).Invoke(); //.Click(); //If the Click() method must be used, make sure to make the window focused first //and the Click() could have to be called a few times for the click to register in the program. }
public static void SetEditControlInputByText(Window window, string text, string input) { var inputBox = (TextBox)Retry.Find(() => window.FindFirstDescendant(x => x.ByText(text).And(x.ByControlType(ControlType.Edit))).AsTextBox(), new RetrySettings { Timeout = TimeSpan.FromSeconds(10), Interval = TimeSpan.FromMilliseconds(500) } ); inputBox.WaitUntilClickable(TimeSpan.FromSeconds(5)) .WaitUntilEnabled(TimeSpan.FromSeconds(5)) .Focus(); //Zoom's edit controls implement both LegacyIAccessible and ValuePattern but neither of them implement SetValue Keyboard.Type(input); }