예제 #1
0
        public void ValidateProofingMenu()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                Log.Warning("Test is disabled pre-RS5 because the ability to add the proofing menu did not exist pre-RS5");
                return;
            }

            using (var setup = new TestSetupHelper(new[] { "CommandBarFlyout Tests", "Extra CommandBarFlyout Tests" }))
            {
                Edit textBox = FindElement.ById <Edit>("TextBox");

                Log.Comment("Type \"asdf\" plus a space to create a misspelled word.");
                KeyboardHelper.EnterText(textBox, "asdf ", useKeyboard: true);

                // We know that the word appears at the start of the text box's content,
                // so we'll use a point 10 pixels from the text box's left edge as a point
                // known to be within the word's bounding box.
                Log.Comment("Right-click on the word's location in the text box to get the proofing menu.");
                InputHelper.RightClick(textBox, 10, textBox.BoundingRectangle.Height / 2);

                Log.Comment("Find \"ads\" in the proofing menu to fix the spelling error.");
                var proofingItem = new MenuItem(FindElement.ByNameAndClassName("ads", "MenuFlyoutItem"));
                Log.Comment($"Invoke {proofingItem}");
                proofingItem.InvokeAndWait();

                Verify.AreEqual("ads ", textBox.Value);
            }
        }
예제 #2
0
        public void CanSelectSuggestion()
        {
            using (var setup = new TestSetupHelper("AutoSuggestBox Tests"))
            {
                Edit autoSuggestBoxTextBox = new Edit(FindElement.ByNameAndClassName("AutoSuggestBox with suggestions", "TextBox"));
                FocusHelper.SetFocus(autoSuggestBoxTextBox);
                KeyboardHelper.EnterText(autoSuggestBoxTextBox, "test");
                KeyboardHelper.PressKey(Key.Enter);
                InvokeImplementation dolorItem = new InvokeImplementation(FindElement.ByNameAndClassName("dolor", "ListViewItem"));

                using (ValueChangedEventWaiter waiter = new ValueChangedEventWaiter(autoSuggestBoxTextBox, "dolor"))
                {
                    dolorItem.Invoke();
                }

                Verify.AreEqual("dolor", autoSuggestBoxTextBox.Value);
            }
        }
        public void AutomationNameIsForwardedToPopup()
        {
            using (var setup = new TestSetupHelper("TeachingTip Tests"))
            {
                elements = new TeachingTipTestPageElements();
                foreach (TipLocationOptions location in Enum.GetValues(typeof(TipLocationOptions)))
                {
                    SetTeachingTipLocation(location);

                    ScrollTargetIntoView();
                    ScrollBy(10);
                    OpenTeachingTip();
                    Verify.IsNotNull(FindElement.ByNameAndClassName(location == TipLocationOptions.VisualTree ? "TeachingTipInVisualTree" : "TeachingTipInResources", "Popup"));
                    SetAutomationName(AutomationNameOptions.None);
                    Verify.IsNotNull(FindElement.ByNameAndClassName("We've Added Auto Saving!", "Popup"));
                    SetAutomationName(location == TipLocationOptions.VisualTree ? AutomationNameOptions.VisualTree : AutomationNameOptions.Resources);
                    CloseTeachingTipProgrammatically();
                }
            }
        }
예제 #4
0
        // this function returns true for successful run and false for unsuccessful run
        // in case of false, the calling function will retry calling this function
        private bool TestSingleRun(ICollection <string> testNames, bool shouldRestrictInnerFrameSize)
        {
            PreTestSetup();

            // We were hitting an issue in the lab where sometimes the very first click would fail to go through resulting in
            // test instability. We work around this by clicking on element when the app launches.
            if (!string.IsNullOrEmpty(Options.AutomationIdOfSafeItemToClick))
            {
                var safeItemToClick = FindElement.ById(Options.AutomationIdOfSafeItemToClick);
                if (safeItemToClick == null)
                {
                    string errorMessage = $"Cannot find object with automation id '{Options.AutomationIdOfSafeItemToClick}'";
                    Log.Warning(errorMessage);
                    DumpHelper.DumpFullContext();
                    return(false);  //retry needed
                }
                InputHelper.LeftClick(safeItemToClick);
            }


            foreach (string testName in testNames)
            {
                Log.Comment(testName + " initializing TestSetupHelper");

                UIObject uiObject;
                if (!String.IsNullOrEmpty(Options.ClassNameOfNavigationItemToInvoke))
                {
                    uiObject = FindElement.ByNameAndClassName(testName, Options.ClassNameOfNavigationItemToInvoke);
                }
                else
                {
                    uiObject = FindElement.ByName(testName);
                }

                if (uiObject == null)
                {
                    string errorMessage = string.Format("Cannot find test page for: {0}.", testName);

                    // We'll raise the error message first so the dump has proper context preceding it,
                    // and will then throw it as an exception so we immediately cease execution.
                    Log.Warning(errorMessage);
                    DumpHelper.DumpFullContext();
                    return(false);   //retry needed
                }

                // We're now entering a new test page, so everything has changed.  As such, we should clear our
                // element cache in order to ensure that we don't accidentally retrieve any stale UI objects.
                ElementCache.Clear();

                Log.Comment("Waiting until __TestContentLoadedCheckBox to be checked by test app.");
                CheckBox cb = new CheckBox(FindElement.ById("__TestContentLoadedCheckBox"));

                using (var waiter = cb.GetToggledWaiter())
                {
                    var testButton = new Button(uiObject);
                    testButton.Invoke();

                    if (cb.ToggleState != ToggleState.On)
                    {
                        waiter.Wait();
                    }
                }

                Wait.ForIdle();

                Log.Comment("__TestContentLoadedCheckBox checkbox checked, page has loaded");

                SetInnerFrameInLabDimensions(shouldRestrictInnerFrameSize);

                OpenedTestPages++;
            }

            TestCleanupHelper.TestSetupHelperPendingDisposals++;

            return(true);  //no retry needed, it is a success
        }
        public void ArrowKeyNavigationTest()
        {
            var testScenarios = RegressionTestScenario.BuildLeftNavRegressionTestScenarios();

            foreach (var testScenario in testScenarios)
            {
                using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", testScenario.TestPageName }))
                {
                    //TODO: Update RS3 and below tab behavior to match RS4+
                    if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone4))
                    {
                        Log.Warning("Test is disabled because the repeater tab behavior is current different rs3 and below.");
                        return;
                    }

                    SetNavViewWidth(ControlWidth.Wide);

                    Button togglePaneButton = new Button(FindElement.ById("TogglePaneButton"));
                    togglePaneButton.SetFocus();
                    Wait.ForIdle();

                    // Grab references to all the menu items in the test UI
                    UIObject searchBox    = FindElement.ByNameAndClassName("PaneAutoSuggestBox", "TextBox");
                    UIObject item1        = FindElement.ByName("Home");
                    UIObject item2        = FindElement.ByName("Apps");
                    UIObject item3        = FindElement.ByName("Games");
                    UIObject item4        = FindElement.ByName("Music");
                    UIObject item5        = FindElement.ByName("Movies");
                    UIObject item6        = FindElement.ByName("TV");
                    UIObject settingsItem = FindElement.ByName("Settings");

                    Log.Comment("Verify that tab from the TogglePaneButton goes to the search box");
                    KeyboardHelper.PressKey(Key.Tab);
                    Wait.ForIdle();
                    Verify.IsTrue(searchBox.HasKeyboardFocus);

                    Log.Comment("Verify that tab from search box goes to the first item");
                    KeyboardHelper.PressKey(Key.Tab);
                    Wait.ForIdle();
                    Verify.IsTrue(item1.HasKeyboardFocus);

                    Log.Comment("Verify that down arrow can navigate through all items");
                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item2.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item3.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item4.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item5.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item6.HasKeyboardFocus);

                    Log.Comment("Verify that tab twice from the last menu item goes to the settings item");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.None, 2);
                    Wait.ForIdle();
                    Verify.IsTrue(settingsItem.HasKeyboardFocus);

                    // TODO: Re-enable test part and remove workaround once saving tab state is fixed

                    Log.Comment("Move Focus to TV item");
                    item6.SetFocus();
                    Wait.ForIdle();

                    //Log.Comment("Verify that shift+tab twice from the settings item goes to the last menu item");
                    //KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 2);
                    //Wait.ForIdle();
                    //Verify.IsTrue(item6.HasKeyboardFocus);

                    Log.Comment("Verify that up arrow can navigate through all items");
                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item5.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item4.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item3.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item2.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item1.HasKeyboardFocus);

                    Log.Comment("Verify that shift+tab from the first menu item goes to the search box");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift);
                    Wait.ForIdle();
                    Verify.IsTrue(searchBox.HasKeyboardFocus);

                    Log.Comment("Verify that shift+tab from the search box goes to the TogglePaneButton");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift);
                    Wait.ForIdle();
                    Verify.IsTrue(togglePaneButton.HasKeyboardFocus);
                }
            }
        }
        public void TabNavigationTest()
        {
            var testScenarios = RegressionTestScenario.BuildLeftNavRegressionTestScenarios();

            foreach (var testScenario in testScenarios)
            {
                using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", testScenario.TestPageName }))
                {
                    //TODO: Update RS3 and below tab behavior to match RS4+
                    if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone4))
                    {
                        Log.Warning("Test is disabled because the repeater tab behavior is current different rs3 and below.");
                        return;
                    }

                    SetNavViewWidth(ControlWidth.Wide);

                    Button   togglePaneButton = new Button(FindElement.ById("TogglePaneButton"));
                    UIObject searchBox        = FindElement.ByNameAndClassName("PaneAutoSuggestBox", "TextBox");
                    UIObject firstItem        = FindElement.ByName("Home");
                    UIObject settingsItem     = FindElement.ByName("Settings");
                    togglePaneButton.SetFocus();
                    Wait.ForIdle();

                    Log.Comment("Verify that pressing tab while TogglePaneButton has focus moves to the search box");
                    KeyboardHelper.PressKey(Key.Tab);
                    Wait.ForIdle();
                    Verify.IsTrue(searchBox.HasKeyboardFocus);

                    Log.Comment("Verify that pressing tab while the search box has focus moves to the first menu item");
                    KeyboardHelper.PressKey(Key.Tab);
                    Wait.ForIdle();
                    Verify.IsTrue(firstItem.HasKeyboardFocus);

                    Log.Comment("Verify that pressing tab twice more will move focus to the settings item");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.None, 2);
                    Wait.ForIdle();
                    Verify.IsTrue(settingsItem.HasKeyboardFocus);

                    // TODO: Re-enable test part and remove workaround once saving tab state is fixed

                    Log.Comment("Move Focus to first item");
                    firstItem.SetFocus();
                    Wait.ForIdle();

                    //Log.Comment("Verify that pressing SHIFT+tab twice will move focus to the first menu item");
                    //KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 2);
                    //Wait.ForIdle();
                    //Verify.IsTrue(firstItem.HasKeyboardFocus);

                    Log.Comment("Verify that pressing SHIFT+tab will move focus to the search box");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 1);
                    Wait.ForIdle();
                    Verify.IsTrue(searchBox.HasKeyboardFocus);

                    Log.Comment("Verify that pressing SHIFT+tab will move focus to the TogglePaneButton");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 1);
                    Wait.ForIdle();
                    Verify.IsTrue(togglePaneButton.HasKeyboardFocus);
                }
            }
        }
예제 #7
0
        // The value of 'testName' should match that which was used when
        // registering the test in TestInventory.cs in the test app project.
        public TestSetupHelper(string testName, string languageOverride = "", bool attemptRestartOnDispose = true)
        {
            // If a test crashes, it can take a little bit of time before we can
            // restart the app again especially if watson is collecting dumps. Adding a
            // delayed retry can help avoid the case where we might otherwise fail a slew of
            // tests that come after the one that crashes the app.
            var retryCount = 10;

            while (retryCount-- > 0)
            {
                try
                {
                    AttemptRestartOnDispose = attemptRestartOnDispose;
                    bool restartedTestApp = false;

                    Log.Comment(testName + " initializing TestSetupHelper");

                    if (TestEnvironment.ShouldRestartApplication)
                    {
                        ElementCache.Clear();
                        Wait.ResetIdleHelper();

                        TestEnvironment.ShouldRestartApplication = false;

                        Log.Comment("Restarting application to ensure test stability...");
                        TestEnvironment.Application.Close();

                        restartedTestApp = true;
                    }

                    if (restartedTestApp ||
                        (TestEnvironment.Application.Process != null && TestEnvironment.Application.Process.HasExited))
                    {
                        if (!restartedTestApp)
                        {
                            // If the test application process exited because something crashed,
                            // we'll restart it in order to make sure that other tests aren't affected.
                            Log.Comment("Application exited unexpectedly. Reinitializing...");
                        }

                        ElementCache.Clear();
                        Wait.ResetIdleHelper();

#if USING_TAEF
                        string deploymentDir = TestEnvironment.TestContext.TestDeploymentDir;
#else
                        // TestDeploymentDir doesn't exist on MSTest's TestContext.  The only thing we use it for
                        // is to install the AppX, and we install the AppX in other ways when using MSTest, so
                        // we don't need it there.
                        string deploymentDir = null;
#endif

                        TestEnvironment.Application.Initialize(true, deploymentDir);
                    }

                    ElementCache.Clear();
                    Wait.ForIdle();

                    // Before we navigate to the test page, we need to make sure that we've set the language to what was requested.
                    var languageChooser = TryFindElement.ById("LanguageChooser");

                    // Sometimes TestSetupHelper is used to navigate off of a page other than the main page.  In those circumstances,
                    // we won't have a pseudo-loc check box on the page, which is fine - we can just skip this step when that's the case,
                    // as we'll have already gone into whatever language we wanted previously.
                    if (languageChooser != null)
                    {
                        ComboBox languageChooserComboBox = new ComboBox(languageChooser);

                        if (!String.IsNullOrEmpty(languageOverride))
                        {
                            languageChooserComboBox.SelectItemById(languageOverride);
                        }
                    }

                    // We were hitting an issue in the lab where sometimes the very first click would fail to go through resulting in
                    // test instability. We work around this by clicking on element when the app launches.
                    var currentPageTextBlock = FindElement.ById("__CurrentPage");
                    if (currentPageTextBlock == null)
                    {
                        string errorMessage = "Cannot find __CurrentPage textblock";
                        Log.Error(errorMessage);
                        DumpHelper.DumpFullContext();
                        throw new InvalidOperationException(errorMessage);
                    }
                    InputHelper.LeftClick(currentPageTextBlock);

                    var uiObject = FindElement.ByNameAndClassName(testName, "Button");
                    if (uiObject == null)
                    {
                        string errorMessage = string.Format("Cannot find test page for: {0}.", testName);

                        // We'll raise the error message first so the dump has proper context preceding it,
                        // and will then throw it as an exception so we immediately cease execution.
                        Log.Error(errorMessage);
                        DumpHelper.DumpFullContext();
                        throw new InvalidOperationException(errorMessage);
                    }

                    // We're now entering a new test page, so everything has changed.  As such, we should clear our
                    // element cache in order to ensure that we don't accidentally retrieve any stale UI objects.
                    ElementCache.Clear();

                    Log.Comment("Waiting until __TestContentLoadedCheckBox to be checked by test app.");
                    CheckBox cb = new CheckBox(FindElement.ById("__TestContentLoadedCheckBox"));

                    if (cb.ToggleState != ToggleState.On)
                    {
                        using (var waiter = cb.GetToggledWaiter())
                        {
                            var testButton = new Button(uiObject);
                            testButton.Invoke();
                            Wait.ForIdle();
                            waiter.Wait();
                        }
                    }
                    else
                    {
                        var testButton = new Button(uiObject);
                        testButton.Invoke();
                    }

                    Wait.ForIdle();

                    Log.Comment("__TestContentLoadedCheckBox checkbox checked, page has loaded");

                    TestCleanupHelper.TestSetupHelperPendingDisposals++;

                    break;
                }
                catch
                {
                    Log.Warning("Failed to setup test. pending retries: " + retryCount);
                    if (retryCount > 0)
                    {
                        Log.Comment("Waiting before retry...");
                        TestEnvironment.ShouldRestartApplication = true;
                        Task.Delay(5000);
                    }
                    else
                    {
                        Log.Error("Failed to set up test!");
                        try
                        {
                            DumpHelper.DumpFullContext();
                        }
                        catch (Exception e)
                        {
                            Log.Error("Also failed to dump context because of an exception: {0}", e.ToString());
                        }

                        throw;
                    }
                }
            }
        }
예제 #8
0
        public void ArrowKeyNavigationTest()
        {
            var testScenarios = RegressionTestScenario.BuildLeftNavRegressionTestScenarios();

            foreach (var testScenario in testScenarios)
            {
                using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", testScenario.TestPageName }))
                {
                    //TODO: Update RS3 and below tab behavior to match RS4+
                    if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone4))
                    {
                        Log.Warning("Test is disabled because the repeater tab behavior is current different rs3 and below.");
                        return;
                    }

                    SetNavViewWidth(ControlWidth.Wide);

                    // Clear any item selection
                    var clearSelectedItemButton = new Button(FindElement.ByName("ClearSelectedItemButton"));
                    clearSelectedItemButton.Click();
                    Wait.ForIdle();

                    Verify.AreEqual("null", GetSelectedItem());

                    Button togglePaneButton = new Button(FindElement.ById("TogglePaneButton"));
                    togglePaneButton.SetFocus();
                    Wait.ForIdle();

                    // Grab references to all the menu items in the test UI
                    UIObject searchBox    = FindElement.ByNameAndClassName("PaneAutoSuggestBox", "TextBox");
                    UIObject item1        = FindElement.ByName("Home");
                    UIObject item2        = FindElement.ByName("Apps");
                    UIObject item3        = FindElement.ByName("Games");
                    UIObject item4        = FindElement.ByName("Music");
                    UIObject item5        = FindElement.ByName("Movies");
                    UIObject item6        = FindElement.ByName("TV");
                    UIObject item7        = FindElement.ByName("Volume");
                    UIObject item8        = FindElement.ByName("Integer");
                    UIObject item9        = FindElement.ByName("HasChildItem");
                    UIObject settingsItem = FindElement.ByName("Settings");

                    Log.Comment("Verify that tab from the TogglePaneButton goes to the search box");
                    KeyboardHelper.PressKey(Key.Tab);
                    Wait.ForIdle();
                    Verify.IsTrue(searchBox.HasKeyboardFocus);

                    Log.Comment("Verify that tab from search box goes to the first item");
                    KeyboardHelper.PressKey(Key.Tab);
                    Wait.ForIdle();
                    Verify.IsTrue(item1.HasKeyboardFocus);

                    Log.Comment("Verify that down arrow can navigate through all items");
                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item2.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item3.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item4.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item5.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item6.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item7.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item8.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Down);
                    Wait.ForIdle();
                    Verify.IsTrue(item9.HasKeyboardFocus);

                    Log.Comment("Verify that tab thrice from the last menu item goes to the settings item");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.None, 3);
                    Wait.ForIdle();
                    Verify.IsTrue(settingsItem.HasKeyboardFocus);

                    Log.Comment("Verify that shift+tab thrice from the settings item goes to the last menu item");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 3);
                    Wait.ForIdle();
                    Verify.IsTrue(item9.HasKeyboardFocus);

                    Log.Comment("Verify that up arrow can navigate through all items");
                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item8.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item7.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item6.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item5.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item4.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item3.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item2.HasKeyboardFocus);

                    KeyboardHelper.PressKey(Key.Up);
                    Wait.ForIdle();
                    Verify.IsTrue(item1.HasKeyboardFocus);

                    Log.Comment("Verify that shift+tab from the first menu item goes to the search box");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift);
                    Wait.ForIdle();
                    Verify.IsTrue(searchBox.HasKeyboardFocus);

                    Log.Comment("Verify that shift+tab from the search box goes to the TogglePaneButton");
                    KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift);
                    Wait.ForIdle();
                    Verify.IsTrue(togglePaneButton.HasKeyboardFocus);
                }

                string GetSelectedItem()
                {
                    return(FindElement.ByName("SelectionChangedItemType").GetText());
                }
            }
        }
예제 #9
0
        public void TabNavigationTest()
        {
            var testScenarios = RegressionTestScenario.BuildLeftNavRegressionTestScenarios();

            foreach (var testScenario in testScenarios)
            {
                using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", testScenario.TestPageName }))
                {
                    // TODO: Update RS3 and below tab behavior to match RS4+
                    if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone4))
                    {
                        Log.Warning("Test is disabled because the repeater tab behavior is currently different on RS3 and below.");
                        return;
                    }

                    SetNavViewWidth(ControlWidth.Wide);

                    Button   togglePaneButton = new Button(FindElement.ById("TogglePaneButton"));
                    UIObject searchBox        = FindElement.ByNameAndClassName("PaneAutoSuggestBox", "TextBox");
                    UIObject settingsItem     = FindElement.ByName("Settings");

                    VerifyTabNavigationWithoutMenuItemSelected();
                    VerifyTabNavigationWithMenuItemSelected();

                    void VerifyTabNavigationWithoutMenuItemSelected()
                    {
                        Log.Comment("Verify Tab navigation without a selected menu item");

                        // Clear any item selection
                        var clearSelectedItemButton = new Button(FindElement.ByName("ClearSelectedItemButton"));

                        clearSelectedItemButton.Click();
                        Wait.ForIdle();

                        Verify.AreEqual("null", GetSelectedItem());

                        UIObject firstMenuItem = FindElement.ByName("Home");
                        UIObject lastMenuItem  = FindElement.ByName("HasChildItem");

                        // Set focus on the pane's toggle button.
                        togglePaneButton.SetFocus();
                        Wait.ForIdle();

                        Log.Comment("Verify that pressing tab while TogglePaneButton has focus moves to the search box");
                        KeyboardHelper.PressKey(Key.Tab);
                        Wait.ForIdle();
                        Verify.IsTrue(searchBox.HasKeyboardFocus);

                        Log.Comment("Verify that pressing tab while the search box has focus moves to the first menu item");
                        KeyboardHelper.PressKey(Key.Tab);
                        Wait.ForIdle();
                        Verify.IsTrue(firstMenuItem.HasKeyboardFocus);

                        Log.Comment("Verify that pressing tab thrice more will move focus to the settings item");
                        KeyboardHelper.PressKey(Key.Tab, ModifierKey.None, 3);
                        Wait.ForIdle();
                        Verify.IsTrue(settingsItem.HasKeyboardFocus);

                        Log.Comment("Verify that pressing SHIFT+tab thrice will move focus to the last menu item");
                        KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 3);
                        Wait.ForIdle();
                        Verify.IsTrue(lastMenuItem.HasKeyboardFocus);

                        Log.Comment("Verify that pressing SHIFT+tab will move focus to the search box");
                        KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 1);
                        Wait.ForIdle();
                        Verify.IsTrue(searchBox.HasKeyboardFocus);

                        Log.Comment("Verify that pressing SHIFT+tab will move focus to the TogglePaneButton");
                        KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 1);
                        Wait.ForIdle();
                        Verify.IsTrue(togglePaneButton.HasKeyboardFocus);
                    }

                    void VerifyTabNavigationWithMenuItemSelected()
                    {
                        Log.Comment("Verify Tab navigation with a selected menu item");

                        // Select a menu item (preferably not the first or last menu item)
                        UIObject thirdMenuItem = FindElement.ByName("Games");

                        var selectedItemComboBox = new ComboBox(FindElement.ById("SelectedItemCombobox"));

                        selectedItemComboBox.SelectItemByName("Games");
                        Wait.ForIdle();

                        Verify.IsTrue(Convert.ToBoolean(thirdMenuItem.GetProperty(UIProperty.Get("SelectionItem.IsSelected"))));

                        // Set focus on the pane's toggle button.
                        togglePaneButton.SetFocus();
                        Wait.ForIdle();

                        Log.Comment("Verify that pressing tab while TogglePaneButton has focus moves to the search box");
                        KeyboardHelper.PressKey(Key.Tab);
                        Wait.ForIdle();
                        Verify.IsTrue(searchBox.HasKeyboardFocus);

                        Log.Comment("Verify that pressing tab while the search box has focus moves to the selected menu item");
                        KeyboardHelper.PressKey(Key.Tab);
                        Wait.ForIdle();
                        Verify.IsTrue(thirdMenuItem.HasKeyboardFocus);

                        Log.Comment("Verify that pressing tab thrice more will move focus to the settings item");
                        KeyboardHelper.PressKey(Key.Tab, ModifierKey.None, 3);
                        Wait.ForIdle();
                        Verify.IsTrue(settingsItem.HasKeyboardFocus);

                        Log.Comment("Verify that pressing SHIFT+tab thrice will move focus to the selected menu item");
                        KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 3);
                        Wait.ForIdle();
                        Verify.IsTrue(thirdMenuItem.HasKeyboardFocus);

                        Log.Comment("Verify that pressing SHIFT+tab will move focus to the search box");
                        KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 1);
                        Wait.ForIdle();
                        Verify.IsTrue(searchBox.HasKeyboardFocus);

                        Log.Comment("Verify that pressing SHIFT+tab will move focus to the TogglePaneButton");
                        KeyboardHelper.PressKey(Key.Tab, ModifierKey.Shift, 1);
                        Wait.ForIdle();
                        Verify.IsTrue(togglePaneButton.HasKeyboardFocus);
                    }
                }

                string GetSelectedItem()
                {
                    return(FindElement.ByName("SelectionChangedItemType").GetText());
                }
            }
        }