public static UIObject ByNameAndClassName(UIObject root, string name, string className, bool shouldWait) { UICondition condition = UICondition.CreateFromName(name).AndWith(UICondition.CreateFromClassName(className)); UIObject uiObject = null; root.Descendants.TryFind(condition, out uiObject); if (shouldWait && !root.Descendants.TryFind(condition, out uiObject)) { Log.Comment("Object name = '{0}' className = '{1}' didn't exist, waiting...", name, className); try { TestEnvironment.WaitUntilElementLoadedByName(name); TestEnvironment.WaitUntilElementLoadedByClassName(className); } catch (WaiterTimedOutException) { Log.Error("Could not find object with condition '{0}'!", condition.ToString()); DumpHelper.DumpFullContext(); throw; } root.Descendants.TryFind(condition, out uiObject); Log.Comment("...Found"); } return(uiObject); }
private UIObject LaunchUWPApp(string packageName) { Debug.Assert(_isUWPApp); var nameCondition = UICondition.CreateFromName(packageName); var topLevelWindowCondition = CreateTopLevelWindowCondition().AndWith(nameCondition); return(UAPApp.Launch(_appName, topLevelWindowCondition)); }
public static void SetFocus(UIObject control) { if (!control.HasKeyboardFocus) { var uiCondition = string.IsNullOrEmpty(control.AutomationId) ? UICondition.CreateFromName(control.Name) : UICondition.CreateFromId(control.AutomationId); using (var focusChangedWaiter = new FocusAcquiredWaiter(uiCondition)) { control.SetFocus(); focusChangedWaiter.Wait(); } } }
private UIObject LaunchNonUWPApp(string packageName) { Debug.Assert(!_isUWPApp); var nameCondition = UICondition.CreateFromName(packageName); var topLevelWindowCondition = UICondition.CreateFromClassName("Window").AndWith(nameCondition); UIObject coreWindow = null; try { coreWindow = UAPApp.Launch(_appName, topLevelWindowCondition); } catch { // UAP.Launch launches the app, but fails trying to find a CoreWindow in the launched app. If the // App is not UWP (as in the case of WPF app hosting a XAML Island), We can fallback to looking for // just a window and use it as the root for future queries. // not a uwp app, see if we can find any window with the condition that matches. coreWindow = FindCore.ByNameAndClassName(root: UIObject.Root, name: packageName, className: "Window", shouldWait: true); } return(coreWindow); }
public void ValidateUnhandledKeysOnNonTransientFlyoutDoNotCloseFlyout() { if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.NineteenH1)) { Log.Warning("Test is disabled pre-19H1 because the bug fix needed to support this were not available pre-19H1."); return; } using (var setup = new TextCommandBarFlyoutTestSetupHelper()) { Log.Comment("Give focus to the RichEditBox."); FocusHelper.SetFocus(FindElement.ById("RichEditBox")); using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("Bold"))) { Log.Comment("Double-tap to select a word and bring up the context menu. The Bold button should get focus."); KeyboardHelper.PressKey(Key.F10, ModifierKey.Shift); waiter.Wait(); } Log.Comment("Press the down arrow key. Focus should stay in the flyout."); KeyboardHelper.PressKey(Key.Down); Wait.ForIdle(); Log.Comment("Press the up arrow key. Focus should stay in the flyout."); KeyboardHelper.PressKey(Key.Up); Wait.ForIdle(); using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromId("RichEditBox"))) { Log.Comment("Use Escape to close the context menu. The RichEditBox should now have focus."); KeyboardHelper.PressKey(Key.Escape); waiter.Wait(); } } }
public void ValidateKeyboarding() { if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5)) { Log.Warning("Test is disabled pre-RS5 because the keyboarding fixes needed to support this were not available pre-RS5."); return; } using (var setup = new TextCommandBarFlyoutTestSetupHelper()) { Log.Comment("Give focus to the TextBox."); var textBox = FindElement.ById("TextBox"); FocusHelper.SetFocus(textBox); using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("Select All"))) { Log.Comment("Use Shift+F10 to bring up the context menu. The Select All button should get focus."); KeyboardHelper.PressKey(Key.F10, ModifierKey.Shift); waiter.Wait(); } using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromId("TextBox"))) { Log.Comment("Use Escape to close the context menu. The TextBox should now have focus."); KeyboardHelper.PressKey(Key.Escape); // On 19H1, there's a bug with the focus restoration code, so we'll manually restore focus to allow the rest of the test to run. if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1)) { textBox.SetFocus(); } waiter.Wait(); } Log.Comment("Give focus to the RichEditBox."); var richEditBox = FindElement.ById("RichEditBox"); FocusHelper.SetFocus(richEditBox); using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("Bold"))) { Log.Comment("Use Shift+F10 to bring up the context menu. The Bold button should get focus."); KeyboardHelper.PressKey(Key.F10, ModifierKey.Shift); waiter.Wait(); } Log.Comment("Press the spacebar to invoke the bold button. Focus should stay in the flyout."); KeyboardHelper.PressKey(Key.Space); Wait.ForIdle(); using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("More app bar"))) { Log.Comment("Press the right arrow key three times. The '...' button should get focus."); KeyboardHelper.PressKey(Key.Right, ModifierKey.None, numPresses: 3); waiter.Wait(); } using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("Select All"))) { Log.Comment("Press the down arrow key twice. The Select All button should get focus."); KeyboardHelper.PressKey(Key.Down, ModifierKey.None, numPresses: 2); waiter.Wait(); } using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromId("RichEditBox"))) { Log.Comment("Use Escape to close the context menu. The RichEditBox should now have focus."); KeyboardHelper.PressKey(Key.Escape); // On 19H1, there's a bug with the focus restoration code, so we'll manually restore focus to allow the rest of the test to run. if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1)) { richEditBox.SetFocus(); } waiter.Wait(); } } }