public void VerifyAlwaysExpandedBehavior() { if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2)) { Log.Warning("Test is disabled pre-RS2 because CommandBarFlyout is not supported pre-RS2"); return; } using (var setup = new CommandBarFlyoutTestSetupHelper()) { Button showCommandBarFlyoutButton = FindElement.ByName <Button>("Show CommandBarFlyout with AlwaysExpanded"); Log.Comment("Tapping on a button to show the CommandBarFlyout."); showCommandBarFlyoutButton.InvokeAndWait(); Log.Comment("Verifying that the secondary commands are visible."); Button undoButton = FindElement.ById <Button>("UndoButton9"); Verify.IsNotNull(undoButton); Log.Comment("Verifying that the ... button is not visible."); UIObject moreButton = TryFindElement.ById("MoreButton"); Verify.IsNull(moreButton); Log.Comment("Tapping on one of the primary commands"); FindElement.ById <Button>("CutButton9").InvokeAndWait(); ElementCache.Clear(); Log.Comment("Verifying that the secondary commands are still visible."); undoButton = FindElement.ById <Button>("UndoButton9"); Verify.IsNotNull(undoButton); Log.Comment("Tapping on a button to hide the CommandBarFlyout."); InputHelper.Tap(showCommandBarFlyoutButton); } }
public static void VerifyAreEqualWithRetry(int maxRetries, Func <object> expectedFunc, Func <object> actualFunc, Action retryAction = null) { if (retryAction == null) { retryAction = () => { Task.Delay(TimeSpan.FromMilliseconds(50)).Wait(); ElementCache.Clear(); /* Test is flaky sometimes -- perhaps element cache is stale? Clear it and try again. */ }; } for (int retry = 0; retry <= maxRetries; retry++) { object expected = expectedFunc(); object actual = actualFunc(); if (Object.Equals(expected, actual) || retry == maxRetries) { Log.Comment("Actual retry times: " + retry); Verify.AreEqual(expected, actual); return; } else { retryAction(); } } }
public void VerifyNumberBoxHeaderBehavior() { using (var setup = new TestSetupHelper("NumberBox Tests")) { var toggleHeaderButton = FindElement.ByName <Button>("ToggleHeaderValueButton"); var header = FindElement.ByName <TextBlock>("NumberBoxHeaderClippingDemoHeader"); Log.Comment("Check header is null"); Verify.IsNull(header); Log.Comment("Set header"); toggleHeaderButton.Invoke(); Wait.ForIdle(); header = FindElement.ByName <TextBlock>("NumberBoxHeaderClippingDemoHeader"); Log.Comment("Check if header is present"); Verify.IsNotNull(header); Log.Comment("Remove header"); toggleHeaderButton.Invoke(); Wait.ForIdle(); ElementCache.Clear(); Log.Comment("Check that header is null again"); header = FindElement.ByName <TextBlock>("NumberBoxHeaderClippingDemoHeader"); Verify.IsNull(header); } }
public void VerifyNavigationViewItemResponseToClickAfterBeingMovedBetweenFrames() { using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "NavigationView Init Test" })) { var myLocationButton = FindElement.ByName <Button>("MyLocation"); var switchFrameButton = FindElement.ByName <Button>("SwitchFrame"); var result = new TextBlock(FindElement.ByName("MyLocationResult")); Log.Comment("Click on MyLocation Item and verify it's on Frame1"); myLocationButton.Click(); Wait.ForIdle(); Verify.AreEqual(result.GetText(), "Frame1"); Log.Comment("Click on SwitchFrame"); switchFrameButton.Click(); Wait.ForIdle(); // tree structure changed and rebuild the cache. ElementCache.Clear(); Log.Comment("Click on MyLocation Item and verify it's on Frame2"); myLocationButton = FindElement.ByName <Button>("MyLocation"); myLocationButton.Click(); Wait.ForIdle(); Verify.AreEqual(result.GetText(), "Frame2"); } }
public UIObject GetTeachingTipCloseButton() { ElementCache.Clear(); var element = GetElement(ref teachingTipCloseButton, "C:Short Text."); teachingTipCloseButton = null; return(element); }
public UIObject GetTeachingTipAlternateCloseButton() { ElementCache.Clear(); var element = GetElement(ref teachingTipAlternateCloseButton, "Close"); teachingTipAlternateCloseButton = null; return(element); }
public void GoBack() { Log.Comment("Going to the previous page..."); // The System Back button sometimes cannot be found at the first attempt, // or invoking it sometimes fails. Retry a few times. for (int retries = 0; ; retries++) { try { // If the process has closed prematurely, then there's no back button to press, // so we'll just no-op. if (Process.HasExited) { Log.Comment("Process already exited"); return; } Log.Comment("Invoking the back button..."); FindElement.ById <Button>("__GoBackInvoker").InvokeAndWait(); Log.Comment("Invoke successful."); // We're now exiting the page we were previously on, 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(); // Successfully found and invoked the Back button. Exit the retry loop. break; } catch (Exception e) { string log = "Failed to find and invoke Back button. Error: " + e.ToString(); if (retries == 10) { Log.Error(log); DumpHelper.DumpFullContext(); throw; } else { Log.Warning(log); if (retries % 2 == 0) { Log.Comment("Clearing element cache which may be stale."); ElementCache.Clear(); } Log.Comment("Back button was not found. Trying again ({0}).", retries); Thread.Sleep(150); } } } }
public void VerifyOverflowButtonIsCollapsedWhenOverflowMenuIsEmpty() { using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "Top NavigationView Overflow Button Test" })) { VerifyOverflowButtonIsVisibleAndOverflowMenuHasSingleItem(); Log.Comment("Verify that removing the final overflow menu item collapses the overflow button"); FindElement.ByName <Button>("RemoveLastItemButton").InvokeAndWait(); // Refresh the cache to make sure that the overflow button we are going to be searching for // does not return as a false positive due to the caching mechanism. ElementCache.Clear(); VerifyOverflowButtonIsCollapsed(); Log.Comment("Add menu item to show the overflow button again with the overflow menu item containing a single item"); FindElement.ByName <Button>("AddItem4Button").InvokeAndWait(); VerifyOverflowButtonIsVisibleAndOverflowMenuHasSingleItem(); Log.Comment("Verify that removing a primary menu item which creates enough room for the single overflow menu item to be moved into collapses the overflow button"); FindElement.ByName <Button>("RemoveFirstItemButton").InvokeAndWait(); // Refresh the cache to make sure that the overflow button we are going to be searching for // does not return as a false positive due to the caching mechanism. ElementCache.Clear(); VerifyOverflowButtonIsCollapsed(); void VerifyOverflowButtonIsVisibleAndOverflowMenuHasSingleItem() { UIObject overflowButton = FindElement.ById("TopNavOverflowButton"); Verify.IsNotNull(overflowButton, "The overflow button is required to be visible for this test"); Log.Comment("Verify that the overflow menu contains a single item"); overflowButton.Click(); Wait.ForIdle(); int numOverflowMenuItems = GetTopNavigationItems(TopNavPosition.Overflow).Count; Verify.IsTrue(numOverflowMenuItems == 1, "The overflow menu should only contain a single item"); } void VerifyOverflowButtonIsCollapsed() { UIObject overflowButton = FindElement.ById("TopNavOverflowButton"); Verify.IsNull(overflowButton, "The overflow button should have been collapsed"); } } }
protected void EnsurePaneHeaderCanBeModifiedHelper(RegressionTestType navviewMode) { if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2)) { Log.Warning("Test is disabled on RS1 and earlier because Pane Header is on RS2."); return; } if (navviewMode == RegressionTestType.TopNav) { var flipOrientationButton = new Button(FindElement.ByName("FlipOrientationButton")); flipOrientationButton.Invoke(); Wait.ForIdle(); } var changePaneHeaderbutton = new Button(FindElement.ByName("ChangePaneHeader")); changePaneHeaderbutton.Invoke(); Wait.ForIdle(); UIObject paneHeaderContent = null; if (navviewMode == RegressionTestType.TopNav) { paneHeaderContent = FindElement.ById("PaneHeaderOnTopPane"); } else { paneHeaderContent = FindElement.ById("PaneHeaderContentBorder"); } TextBlock text = new TextBlock(paneHeaderContent.FirstChild); Verify.AreEqual("Modified Pane Header", text.DocumentText); if (navviewMode == RegressionTestType.LeftNav) { // In Closed Compact mode, the PaneHeader should not be visible: var panelDisplayModeComboBox = new ComboBox(FindElement.ByName("PaneDisplayModeCombobox")); panelDisplayModeComboBox.SelectItemByName("LeftCompact"); Wait.ForIdle(); EnsureNavViewClosed(); ElementCache.Clear(); VerifyElement.NotFound("PaneHeaderContentBorder", FindBy.Name); } }
public void AccessibilityViewTest() { using (var setup = new TestSetupHelper("InfoBar Tests")) { StatusBar infoBar = FindElement.ByName <StatusBar>("TestInfoBar"); Verify.IsNotNull(infoBar, "TestInfoBar should be visible by default"); Log.Comment("Close InfoBar and make sure it can't be found."); Uncheck("IsOpenCheckBox"); ElementCache.Clear(); infoBar = FindElement.ByName <StatusBar>("TestInfoBar"); Verify.IsNull(infoBar, "TestInfoBar should not be in the accessible tree"); infoBar = FindElement.ByName <StatusBar>("DefaultInfoBar"); Verify.IsNull(infoBar, "By default, Infobar should not be visible"); } }
public void HoveringBehaviorTest() { // Overlay pass through element is only available from IFlyoutBase3 forward // On OS versions below RS5 test is unreliable/not working. // Tracked by https://github.com/Microsoft/microsoft-ui-xaml/issues/115 if (PlatformConfiguration.IsDevice(DeviceType.Phone) || !ApiInformation.IsTypePresent("Windows.UI.Xaml.Controls.Primitives.IFlyoutBase3") || PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone4)) { Log.Comment("Skipping tests on phone, because menubar is not supported."); return; } using (var setup = new TestSetupHelper("MenuBar Tests")) { var menuBar = FindElement.ById("SizedMenuBar"); var addButton = FindElement.ByName("AddItemsToEmptyMenuBar"); addButton.Click(); addButton.Click(); addButton.Click(); var help0 = FindElement.ByName <Button>("Help0"); var help1 = FindElement.ByName <Button>("Help1"); // This behavior seems to a bit unreliable, so repeat InputHelper.LeftClick(help0); TestEnvironment.VerifyAreEqualWithRetry(20, () => FindCore.ByName("Add0", shouldWait: false) != null, // The item should be in the tree () => true); // Check if hovering over the next button actually will show the correct item VerifyElement.NotFound("Add1", FindBy.Name); InputHelper.MoveMouse(help1, 0, 0); InputHelper.MoveMouse(help1, 1, 1); InputHelper.MoveMouse(help1, 5, 5); UIObject add1Element = null; ElementCache.Clear(); var element = GetElement(ref add1Element, "Add1"); Verify.IsNotNull(add1Element); } }
public void IsClosableTest() { using (var setup = new TestSetupHelper("InfoBar Tests")) { StatusBar infoBar = FindElement.ByName <StatusBar>("TestInfoBar"); Button closeButton = FindCloseButton(infoBar); Verify.IsNotNull(closeButton, "Close button should be visible by default"); Uncheck("IsClosableCheckBox"); ElementCache.Clear(); closeButton = FindCloseButton(infoBar); Verify.IsNull(closeButton, "Close button should not be visible when IsClosable=false"); Check("IsClosableCheckBox"); ElementCache.Clear(); closeButton = FindCloseButton(infoBar); Verify.IsNotNull(closeButton, "Close button should be visible when IsClosable=true"); } }
public void LayoutTest() { using (var setup = new TestSetupHelper("InfoBar Tests")) { ComboBox actionComboBox = FindElement.ByName <ComboBox>("ActionButtonComboBox"); actionComboBox.SelectItemByName("Button"); Check("HasCustomContentCheckBox"); ElementCache.Clear(); StatusBar infoBar = FindElement.ByName <StatusBar>("TestInfoBar"); CheckBox customContent = FindElement.ByName <CheckBox>("CustomContentCheckBox"); // 0: icon; 1: title; 2: message; 3: action button Log.Comment("Verify that title, message, and action button layout is left-to-right"); Verify.IsGreaterThan(infoBar.Children[2].BoundingRectangle.X, infoBar.Children[1].BoundingRectangle.X, "Expect Message to be on the right of Title"); Verify.IsGreaterThan(infoBar.Children[3].BoundingRectangle.X, infoBar.Children[2].BoundingRectangle.X, "Expect action button to be on the right of Message"); VerifyIsPrettyClose(infoBar.Children[2].BoundingRectangle.Y, infoBar.Children[1].BoundingRectangle.Y, "Expect Message to be top-aligned with Title"); Verify.IsGreaterThan(customContent.BoundingRectangle.Y, infoBar.Children[1].BoundingRectangle.Y, "Expect custom content to be on under all other things"); VerifyIsPrettyClose(customContent.BoundingRectangle.X, infoBar.Children[1].BoundingRectangle.X, "Expect custom content to be left-aligned with title"); Log.Comment("Change title and message to long strings"); Edit editTitle = FindElement.ByName <Edit>("TitleTextBox"); Edit editMessage = FindElement.ByName <Edit>("MessageTextBox"); editTitle.SetValueAndWait("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vel orci eros. Sed ut lectus ultrices quam hendrerit sagittis. Cras gravida eleifend eros, eu pulvinar lectus molestie dictum. Vivamus et tellus euismod, dapibus odio vel, volutpat risus."); editMessage.SetValueAndWait("Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent vehicula mauris eu libero pretium ullamcorper."); Log.Comment("Verify that title, message, and action button layout is top-to-bottom"); Verify.IsGreaterThan(infoBar.Children[2].BoundingRectangle.Y, infoBar.Children[1].BoundingRectangle.Y, "Expect Message to be below Title"); Verify.IsGreaterThan(infoBar.Children[3].BoundingRectangle.Y, infoBar.Children[2].BoundingRectangle.Y, "Expect action button to be below Message"); VerifyIsPrettyClose(infoBar.Children[2].BoundingRectangle.X, infoBar.Children[1].BoundingRectangle.X, "Expect Message to be left-aligned with Title"); VerifyIsPrettyClose(infoBar.Children[3].BoundingRectangle.X, infoBar.Children[2].BoundingRectangle.X, "Expect action button to be left-aligned Message"); Verify.IsGreaterThan(customContent.BoundingRectangle.Y, infoBar.Children[3].BoundingRectangle.Y, "Expect custom content to be on under all other things"); VerifyIsPrettyClose(customContent.BoundingRectangle.X, infoBar.Children[1].BoundingRectangle.X, "Expect custom content to be left-aligned with everyone else"); } }
private void PageLoadedTimer_Tick(object sender, EventArgs e) { ElementCache.Clear(); try { var topbox = WebBrowser.Document.GetElementById("nexonCLogin"); if (topbox == null) { return; } } catch { return; } WebBrowser.Document.Body.Style = "background-color: #222222"; //Put Password in passwordbox var passwordBox = WebBrowser.Document.GetElementById("txtCPWD"); if (passwordBox != null) { PageLoadedTimer.Stop(); try { if (tbRememberPassword.Text.Trim() != "") { passwordBox.Focus(); passwordBox.InnerText = tbRememberPassword.Text; } } catch { } //eat it } //Page Cleanup try { var header = GetElementsByAttribMatch("div", "className", "header"); HideElements(header); var gnb = GetElementsByAttribMatch("div", "className", "gnbBarLeft"); HideElements(header); var h1 = WebBrowser.Document.GetElementsByTagName("h1").Cast <HtmlElement>(); HideElements(h1); var forgetPass = GetElementsByAttribMatch("p", "className", "loginMenu"); HideElements(forgetPass); var topbox = WebBrowser.Document.GetElementById("nexonCLogin"); if (topbox != null) { topbox.Style = "padding-top:13px"; } var capcha = GetElementsByAttribMatch("div", "className", "captchaSec"); foreach (var elem in capcha) { elem.Style = "margin: 0 0 0px"; } } catch { } //eat it //page translation try { var btLogin = GetElementsByAttribMatch("div", "className", "btLogin"); foreach (var elem in btLogin) { //for some reason, the login screen REALLY doesn't like it if you touch the button's text... //elem.InnerHtml = elem.InnerHtml.Replace("넥슨ID 로그인", "Log in"); elem.Style = "height: 40px"; } var btnLogin = GetElementsByAttribMatch("button", "className", "button01"); foreach (var elem in btnLogin) { elem.Style = "height: 40px"; } } catch { } //eat it try { var labelSaveUser = GetElementsByAttribMatch("div", "className", "saveid").FirstOrDefault(); if (labelSaveUser != null) { labelSaveUser.Style = "top:8px"; var actualLabel = labelSaveUser.Children.Cast <HtmlElement>().Last(); actualLabel.InnerText = "Remember Nexon ID"; actualLabel.Style = "color: #FFFFFF"; } } catch { } //eat it /* Captcha Changed on Nexon 5/26/2021, removing this functionality, no longer needed. * try * { * var capchaHeader = GetElementsByAttribMatch("p", "className", "captchaMsg");//.FirstOrDefault(); * * var idmarge = capchaHeader.FirstOrDefault().Parent.Children.Cast<HtmlElement>().FirstOrDefault(it => it.GetAttribute("className") == "id"); * * if (idmarge != null) * idmarge.Style = "margin-top:32px"; * * HideElements(capchaHeader); * * } * catch { } //eat it */ WebBrowser.Visible = true; }
public void DisabledItemsAtTopOfColumnKeyboardTest() { if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone3)) { Log.Warning("This test requires RS3+ keyboarding behavior"); return; } using (var setup = new TestSetupHelper("RadioButtons Tests")) { elements = new RadioButtonsTestPageElements(); SetItemType(RadioButtonsSourceType.RadioButton); SetNumberOfColumns(3); foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation))) { SetSource(location); SetNumberOfItems(10); InsertDisabledRadioButton(5); InsertDisabledRadioButton(5); InsertDisabledRadioButton(5); TapOnItem(0); VerifySelectedFocusedIndex(0); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(9); TapOnItem(1); VerifySelectedFocusedIndex(1); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(10); TapOnItem(2); VerifySelectedFocusedIndex(2); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(11); TapOnItem(3); VerifySelectedFocusedIndex(3); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(8); TapOnItem(4); VerifySelectedFocusedIndex(4); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(8); TapOnItem(6); VerifySelectedFocusedIndex(9); KeyboardHelper.PressKey(Key.Left); VerifySelectedFocusedIndex(0); TapOnItem(7); VerifySelectedFocusedIndex(10); KeyboardHelper.PressKey(Key.Left); VerifySelectedFocusedIndex(1); TapOnItem(8); VerifySelectedFocusedIndex(11); KeyboardHelper.PressKey(Key.Left); VerifySelectedFocusedIndex(2); TapOnItem(9); VerifySelectedFocusedIndex(12); KeyboardHelper.PressKey(Key.Left); VerifySelectedFocusedIndex(8); ElementCache.Clear(); } } }
private void PageLoadedTimer_Tick(object sender, EventArgs e) { ElementCache.Clear(); var passwordBox = WebBrowser.Document.GetElementById("txtCPWD"); if (passwordBox != null) { PageLoadedTimer.Stop(); try { if (tbRememberPassword.Text.Trim() != "") { passwordBox.Focus(); passwordBox.InnerText = tbRememberPassword.Text; } } catch { } //eat it try { var header = GetElementsByAttribMatch("div", "className", "header"); HideElements(header); var gnb = GetElementsByAttribMatch("div", "className", "gnbBarLeft"); HideElements(header); var h1 = WebBrowser.Document.GetElementsByTagName("h1").Cast <HtmlElement>(); HideElements(h1); } catch { } //eat it /* Captcha Changed on Nexon 5/26/2021, removing this functionality, no longer needed. * try * { * var capchaHeader = GetElementsByAttribMatch("p", "className", "captchaMsg");//.FirstOrDefault(); * * var idmarge = capchaHeader.FirstOrDefault().Parent.Children.Cast<HtmlElement>().FirstOrDefault(it => it.GetAttribute("className") == "id"); * * if (idmarge != null) * idmarge.Style = "margin-top:32px"; * * HideElements(capchaHeader); * * } * catch { } //eat it */ try { var labelSaveUser = GetElementsByAttribMatch("div", "className", "saveid").FirstOrDefault(); labelSaveUser.Style = "top:8px"; var actualLabel = labelSaveUser.Children.Cast <HtmlElement>().Last(); actualLabel.InnerText = "Remember Nexon ID"; } catch { } //eat it WebBrowser.Visible = true; } }
// [TestMethod] public void VerifyRatingItemFallback() { // This test is actually performed in the test app itself, so go look at RatingControlPage.xaml.cs for the meat of it. using (var setup = new TestSetupHelper("RatingControl Tests")) // This literally clicks the button corresponding to the test page. { if (!PlatformConfiguration.IsOsVersionGreaterThan(OSVersion.Redstone1)) { Log.Warning("Test is disabled on RS1 due to scrolling unreliability"); return; } Log.Comment("Retrieve PointerOverPlaceholderFallbackRating rating control as generic UIElement"); UIObject popRating = FindElement.ById("PointerOverPlaceholderFallbackRating"); Verify.IsNotNull(popRating, "Verifying that we found a UIElement called PointerOverPlaceholderFallbackRating"); InputHelper.ScrollToElement(popRating); popRating.Tap(); // Since on phone it's touch, I do a tap to trigger that. popRating.Click(); Wait.ForIdle(); Log.Comment("Retrieve PointerOverFallbackRating rating control as generic UIElement"); UIObject pointerOver = FindElement.ById("PointerOverFallbackRating"); Verify.IsNotNull(pointerOver, "Verifying that we found a UIElement called PointerOverFallbackRating"); InputHelper.ScrollToElement(pointerOver); pointerOver.Click(); pointerOver.Tap(); Wait.ForIdle(); TextBlock textBlock = new TextBlock(FindElement.ById("UnsetFallbackTextBlock")); Verify.AreEqual("+", textBlock.DocumentText, "Verify Unset glyph falls back onto Glyph"); TextBlock textBlock2 = new TextBlock(FindElement.ById("PlaceholderFallbackTextBlock")); Verify.AreEqual("+", textBlock2.DocumentText, "Verify Placeholder glyph falls back onto Glyph"); TextBlock textBlock3 = new TextBlock(FindElement.ById("DisabledFallbackTextBlock")); Verify.AreEqual("+", textBlock3.DocumentText, "Verify Disabled glyph falls back onto Glyph"); ElementCache.Clear(); TextBlock textBlock4 = new TextBlock(FindElement.ById("PointerOverPlaceholderFallbackTextBlock")); Verify.AreEqual("+", textBlock4.DocumentText, "Verify PointerOverPlaceholder glyph falls back onto Placeholder"); TextBlock textBlock5 = new TextBlock(FindElement.ById("PointerOverFallbackTextBlock")); Verify.AreEqual("+", textBlock5.DocumentText, "Verify PointerOver glyph falls back onto Glyph"); TextBlock textBlock6 = new TextBlock(FindElement.ById("NoFallbackTextBlock")); Verify.AreEqual("+", textBlock6.DocumentText, "Verify a glyph didn't fall back if it wasn't meant to"); // Image: Log.Comment("Retrieve PointerOverPlaceholderImageFallbackRating rating control as generic UIElement"); popRating = FindElement.ById("PointerOverPlaceholderImageFallbackRating"); Verify.IsNotNull(popRating, "Verifying that we found a UIElement called PointerOverPlaceholderImageFallbackRating"); InputHelper.ScrollToElement(popRating); Wait.ForIdle(); popRating.Tap(); // Since on phone it's touch, I do a tap to trigger that. popRating.Click(); Wait.ForIdle(); Log.Comment("Retrieve PointerOverImageFallbackRating rating control as generic UIElement"); pointerOver = FindElement.ById("PointerOverImageFallbackRating"); Verify.IsNotNull(pointerOver, "Verifying that we found a UIElement called PointerOverImageFallbackRating"); pointerOver.Tap(); pointerOver.Click(); Wait.ForIdle(); textBlock = new TextBlock(FindElement.ById("UnsetImageFallbackTextBlock")); Verify.AreEqual("+", textBlock.DocumentText, "Verify Unset image falls back onto Image"); textBlock2 = new TextBlock(FindElement.ById("PlaceholderImageFallbackTextBlock")); Verify.AreEqual("+", textBlock2.DocumentText, "Verify Placeholder image falls back onto Image"); textBlock3 = new TextBlock(FindElement.ById("DisabledImageFallbackTextBlock")); Verify.AreEqual("+", textBlock3.DocumentText, "Verify Disabled image falls back onto Image"); ElementCache.Clear(); textBlock4 = new TextBlock(FindElement.ById("PointerOverPlaceholderImageFallbackTextBlock")); Verify.AreEqual("+", textBlock4.DocumentText, "Verify PointerOverPlaceholder image falls back onto PlaceholderImage"); textBlock5 = new TextBlock(FindElement.ById("PointerOverImageFallbackTextBlock")); Verify.AreEqual("+", textBlock5.DocumentText, "Verify PointerOver image falls back onto Image"); } }
public void DisabledItemsKeyboardTest() { if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone3)) { Log.Warning("This test requires RS3+ keyboarding behavior"); return; } using (var setup = new TestSetupHelper("RadioButtons Tests")) { elements = new RadioButtonsTestPageElements(); SetItemType(RadioButtonsSourceType.RadioButton); SetNumberOfColumns(3); foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation))) { SetSource(location); SetNumberOfItems(10); InsertDisabledRadioButton(10); TapOnItem(7); VerifySelectedFocusedIndex(7); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(9); KeyboardHelper.PressKey(Key.Left); VerifySelectedFocusedIndex(5); KeyboardHelper.PressKey(Key.Down); VerifySelectedFocusedIndex(6); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(9); //There is a known bug here where pressing down or right will put focus //On the first item because RadioButton handles the event. //RadioButtons doesn't catch this because it only catches when the //Last item is focused, but that item is disabled here... //Bug #1654 //KeyboardHelper.PressKey(Key.Down); //VerifySelectedFocusedIndex(9); //KeyboardHelper.PressKey(Key.Right); //VerifySelectedFocusedIndex(9); InsertDisabledRadioButton(6); InsertDisabledRadioButton(6); TapOnItem(1); VerifySelectedFocusedIndex(1); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(10); TapOnItem(2); VerifySelectedFocusedIndex(2); KeyboardHelper.PressKey(Key.Right); VerifySelectedFocusedIndex(11); TapOnItem(5); KeyboardHelper.PressKey(Key.Up); VerifySelectedFocusedIndex(4); KeyboardHelper.PressKey(Key.Down); VerifySelectedFocusedIndex(5); KeyboardHelper.PressKey(Key.Down); VerifySelectedFocusedIndex(8); TapOnItem(8); VerifySelectedFocusedIndex(10); KeyboardHelper.PressKey(Key.Left); VerifySelectedFocusedIndex(1); TapOnItem(9); VerifySelectedFocusedIndex(11); KeyboardHelper.PressKey(Key.Left); VerifySelectedFocusedIndex(2); ElementCache.Clear(); } } }
// 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 }
// 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; } } } }
private void PreTestSetup() { bool restartedTestApp = false; 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(); if (!String.IsNullOrEmpty(Options.LanguageOverride)) { // 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); languageChooserComboBox.SelectItemById(Options.LanguageOverride); } } }
private void VerifyViewMode(ViewMode mode) { // Verify configuration is correct for mode TwoPaneViewMode expectedConfiguration = TwoPaneViewMode.SinglePane; switch (mode) { case ViewMode.LeftRight: case ViewMode.RightLeft: expectedConfiguration = TwoPaneViewMode.Wide; break; case ViewMode.TopBottom: case ViewMode.BottomTop: expectedConfiguration = TwoPaneViewMode.Tall; break; } TextBlock configurationTextBlock = new TextBlock(FindElement.ByName("ConfigurationTextBlock")); Verify.AreEqual(expectedConfiguration.ToString(), configurationTextBlock.DocumentText); // Verify panes are actually being shown correctly ElementCache.Clear(); UIObject paneContent1 = TryFindElement.ByName("Content1"); UIObject paneContent2 = TryFindElement.ByName("Content2"); if (mode != ViewMode.Pane2Only) { Verify.IsNotNull(paneContent1, "Expected to find pane1"); Log.Comment("Content 1 dimensions: " + paneContent1.BoundingRectangle.ToString()); } if (mode != ViewMode.Pane1Only) { Verify.IsNotNull(paneContent2, "Expected to find pane2"); Log.Comment("Content 2 dimensions: " + paneContent2.BoundingRectangle.ToString()); } if (mode == ViewMode.Pane2Only) { Verify.IsNull(paneContent1, "Expected not to find pane1"); } if (mode == ViewMode.Pane1Only) { Verify.IsNull(paneContent2, "Expected not to find pane2"); } switch (mode) { case ViewMode.LeftRight: case ViewMode.RightLeft: Verify.AreEqual(paneContent1.BoundingRectangle.Top, paneContent2.BoundingRectangle.Top, "Verify panes are horizontally aligned"); if (mode == ViewMode.LeftRight) { Verify.IsGreaterThanOrEqual(paneContent2.BoundingRectangle.Left, paneContent1.BoundingRectangle.Right, "Verify left/right pane placement"); } else { Verify.IsGreaterThanOrEqual(paneContent1.BoundingRectangle.Left, paneContent2.BoundingRectangle.Right, "Verify right/left pane placement"); } break; case ViewMode.TopBottom: case ViewMode.BottomTop: Verify.AreEqual(paneContent1.BoundingRectangle.Left, paneContent2.BoundingRectangle.Left, "Verify panes are vertically aligned"); if (mode == ViewMode.TopBottom) { Verify.IsGreaterThanOrEqual(paneContent2.BoundingRectangle.Top, paneContent1.BoundingRectangle.Bottom, "Verify top/bottom pane placement"); } else { Verify.IsGreaterThanOrEqual(paneContent1.BoundingRectangle.Top, paneContent2.BoundingRectangle.Bottom, "Verify bottom/top pane placement"); } break; } }