/// <summary> /// Initializes a new instance of the <see cref="MainScreen"/> class. /// </summary> /// <param name="vpnSession">VPN session.</param> public MainScreen(WindowsDriver <WindowsElement> vpnSession) { var mainView = Utils.WaitUntilFindElement(vpnSession.FindElementByClassName, "MainView"); var mainCard = Utils.WaitUntilFindElement(mainView.FindElementByAccessibilityId, "MainCard"); this.titleElement = Utils.WaitUntilFindElement(mainCard.FindElementByClassName, "HeroText"); this.subtitleElement = Utils.WaitUntilFindElement(mainCard.FindElementByClassName, "HeroSubText"); var settingButtons = Utils.WaitUntilFindElements(mainCard.FindElementsByName, "Settings"); this.vpnOffSettingButton = settingButtons[0]; this.vpnOnSettingButton = settingButtons[1]; this.vpnSwitch = Utils.WaitUntilFindElement(mainCard.FindElementByName, "Toggle"); this.serverListButton = Utils.WaitUntilFindElement(mainView.FindElementByAccessibilityId, "ConnectionNavButton"); this.deviceListButton = Utils.WaitUntilFindElement(mainView.FindElementByName, "My devices"); this.vpnStatus = Utils.WaitUntilFindElement(mainCard.FindElementByName, "VPN status"); }
/// <summary> /// It will get the element of the toast message by using the given parameters. /// </summary> /// <param name="text">The text to match the element to be found.</param> /// <param name="elem">Represents the Enum in the Share class.</param> /// <param name="widget">True if it is a Widget, false if it is a View.</param> public static AppiumWebElement ToastMessage(string text, Element elem = Element.Toast, bool widget = true) { GlobalVar.AndroidDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(GlobalVar.TimeSpan); var xPath = BuildXPath(widget, elem); AppiumWebElement element = null; try { element = GlobalVar.AndroidDriver.FindElementByXPath(xPath + "[@text='" + text + "']"); } catch (Exception ex) { Assert.Fail("ToastMessage threw an exception: " + ex.Message); } return(element); }
public void ShowSpacingTest() { for (int i = 0; i < 2; ++i) { Assert.IsTrue(OpenEditor()); AppiumWebElement spaceAroundSetting = editorWindow.FindElementByAccessibilityId("spaceAroundSetting"); bool spaceAroundSettingValue = spaceAroundSetting.Selected; spaceAroundSetting.Click(); editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); WaitSeconds(1); Assert.AreNotEqual(spaceAroundSettingValue, GetEditZonesSetting <bool>(editorShowSpacing)); } }
/// <summary> /// Initializes a new instance of the <see cref="LastOnboardingScreen"/> class. /// </summary> /// <param name="vpnSession">VPN session.</param> /// <param name="viewClassName">onboarding screen view class name.</param> public LastOnboardingScreen(WindowsDriver <WindowsElement> vpnSession) { var onboardingView = vpnSession.FindElementByClassName("OnboardingView4"); var textBlocks = onboardingView.FindElementsByClassName("TextBlock"); Assert.IsTrue(textBlocks.Count > 2); this.closeButton = vpnSession.FindElementByName("Close"); this.image = vpnSession.FindElementByClassName("Image"); this.title = textBlocks[0]; this.subtitle = textBlocks[1]; this.getStartedButton = vpnSession.FindElementByName("Get started"); Assert.IsNotNull(this.closeButton); Assert.IsNotNull(this.image); Assert.IsNotNull(this.title); Assert.IsNotNull(this.subtitle); Assert.IsNotNull(this.getStartedButton); }
public void SingleMultiActionTestCase() { IList <AppiumWebElement> els = driver.FindElementsByClassName("android.widget.TextView"); var loc1 = els[7].Location; AppiumWebElement target = els[1]; var loc2 = target.Location; TouchAction swipe = new TouchAction(driver); swipe.Press(loc1.X, loc1.Y).Wait(1000) .MoveTo(loc2.X, loc2.Y).Release(); MultiAction multiAction = new MultiAction(driver); multiAction.Add(swipe).Perform(); Assert.AreNotEqual(loc2.Y, target.Location.Y); }
private static void ReturnToMainPage() { // Try to return to main page in case application is started in nested view try { AppiumWebElement backButton = null; do { backButton = NewsApp.FindElementByAccessibilityId("Back"); backButton.Click(); }while (backButton != null); } catch (Exception e) { Console.Write(e); } }
public void ZoneCount() { Assert.IsTrue(OpenEditor()); AppiumWebElement minusButton = editorWindow.FindElementByAccessibilityId("decrementZones"); AppiumWebElement zoneCount = editorWindow.FindElementByAccessibilityId("zoneCount"); int editorZoneCountValue; Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue)); for (int i = editorZoneCountValue - 1, j = 0; i > -5; --i, ++j) { minusButton.Click(); Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue)); Assert.AreEqual(Math.Max(i, 1), editorZoneCountValue); if (j == 0 || i == -4) { editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); WaitSeconds(1); Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting <int>(editorZoneCount)); Assert.IsTrue(OpenEditor()); minusButton = editorWindow.FindElementByAccessibilityId("decrementZones"); zoneCount = editorWindow.FindElementByAccessibilityId("zoneCount"); } } AppiumWebElement plusButton = editorWindow.FindElementByAccessibilityId("incrementZones"); for (int i = 2; i < 45; ++i) { plusButton.Click(); Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue)); Assert.AreEqual(Math.Min(i, 40), editorZoneCountValue); } editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); WaitSeconds(1); Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting <int>(editorZoneCount)); }
public void ElementRotateTestCase() { IOSDriver driver = new IOSDriver(defaultUri, capabilities); server.respondTo("POST", "/element", new Dictionary <string, object> { { "ELEMENT", '5' } }); AppiumWebElement element = (AppiumWebElement)driver.FindElementByIosUIAutomation(".elements()"); server.clear(); server.respondTo("POST", "/appium/device/rotate", null); Dictionary <string, int> parameters = new Dictionary <string, int> { { "x", 114 }, { "y", 198 }, { "duration", 5 }, { "radius", 3 }, { "rotation", 220 }, { "touchCount", 2 } }; element.Rotate(parameters); }
public void HighlightOpacityClearValueButton() { WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); Assert.IsNotNull(editor); editor.Click(); //activate AppiumWebElement clearButton = editor.FindElementByName("Clear value"); Assert.IsNotNull(clearButton); /*element is not pointer- or keyboard interactable.*/ Actions action = new Actions(session); action.MoveToElement(clearButton).Click().Perform(); Assert.AreEqual("\r\n", editor.Text); }
// holds logic to locate elements // return mapping for home screen title public static AppiumWebElement HomeScreenTitle(AndroidDriver <AppiumWebElement> driver) { String locator = "//android.widget.TextView[@text='Taboola Sample App']"; AppiumWebElement homeScreenTitle = null; try { homeScreenTitle = driver.FindElementByXPath(locator); } catch (Exception e) { throw new Exception("homeScreenTitle not found, please check locator:" + Environment.NewLine + locator + Environment.NewLine + "original exception: " + e.Message); } return(homeScreenTitle); }
private void SelectCategory(NcpAppElement categoryElement) { string category1Name = categoryElement.Attributes["category1Name"]; AndroidElement c1Node = AppAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView[1]", new string[] { category1Name }, true); c1Node.Click(); Thread.Sleep(1500); List <AppiumWebElement> cElements = this.GetCategoryElement(categoryElement.Name); AppiumWebElement cElement = cElements[cElements.Count - 1]; Point point = cElement.Location; Size size = cElement.Size; //点击文字上方的图标 AppAccess.Tap(1, point.X + size.Width / 2, point.Y - 80, 100); //cagtegoryElement.Click(); }
public AppiumWebElement WaitForElementDisplayed(AppiumWebElement element, int time = 30) { while (time-- > 0) { try { if (element.Displayed) { return(element); } } catch { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); } } throw new ElementNotVisibleException($"Element {element.Id} is not visible after {time} seconds"); }
// return mapping for menu item "Widget + Feed (Scroll View)" public static AppiumWebElement WidgetFeedScrollView(AndroidDriver <AppiumWebElement> driver) { String locator = "//android.widget.Button[@text = 'Widget + Feed (ScrollView)']"; AppiumWebElement widgetFeedScrollViewButton = null; try { widgetFeedScrollViewButton = driver.FindElementByXPath(locator); } catch (Exception e) { throw new Exception("widgetFeedScrollViewButton not found, please check locator:" + Environment.NewLine + locator + Environment.NewLine + "original exception: " + e.Message); } return(widgetFeedScrollViewButton); }
/// <summary> /// Sets the switch value to On / Off. /// </summary> /// <param name="bySelector">Selector for switch.</param> /// <param name="value">Value to be selected on switch.</param> public static void SetSwitchValue(By bySelector, eSwitchValue value) { AppiumWebElement switchElement = null; try { switchElement = FindElement(bySelector); string currentSwitchValue = switchElement.GetAttribute("value"); if ((value == eSwitchValue.Off && currentSwitchValue.Equals("1")) || (value == eSwitchValue.On && currentSwitchValue.Equals("0"))) { Click(switchElement); } } catch (Exception e) { PrintException(e); } }
/// <summary> /// Initializes a new instance of the <see cref="WindowsNotificationScreen"/> class. /// </summary> /// <param name="desktopSession">Desktop session.</param> public WindowsNotificationScreen(WindowsDriver <WindowsElement> desktopSession) { try { WindowsElement notification = Utils.WaitUntilFindElement(desktopSession.FindElementByAccessibilityId, "NormalToastView"); this.titleText = notification.FindElementByAccessibilityId("TitleText"); this.messageText = notification.FindElementByAccessibilityId("MessageText"); this.dismissButton = notification.FindElementByAccessibilityId("DismissButton"); } catch (Exception) { Utils.WaitUntilFindElement(desktopSession.FindElementByName, "Action Center").Click(); var notification = Utils.WaitUntilFindElement(desktopSession.FindElementByName, "Notifications from Firefox Private Network VPN"); var latestNotification = notification.FindElementByClassName("ListViewItem"); this.titleText = latestNotification.FindElementByAccessibilityId("Title"); this.messageText = latestNotification.FindElementByAccessibilityId("Content"); this.dismissButton = latestNotification.FindElementByAccessibilityId("DismissButton"); } }
public static void SetCheckBox(AppiumWebElement dialog, string checkBoxId, bool isToCheck) { var checkBox = dialog.FindElementByAccessibilityId(checkBoxId); if (isToCheck) { if (!checkBox.Selected) { checkBox.Click(); } } else { if (checkBox.Selected) { checkBox.Click(); } } }
public string ReadLocalTime() { string localTimeText = ""; AppiumWebElement worldClockPivotItem = AlarmClockSession.FindElementByAccessibilityId("WorldClockPivotItem"); if (worldClockPivotItem != null) { localTimeText = worldClockPivotItem.FindElementByClassName("ClockCardItem").Text; var timeStrings = localTimeText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (timeStrings.Length >= 5) { // Get the time. E.g. "Local time, Monday, February 22, 2016, 11:32 AM, " localTimeText = timeStrings[4]; } } return(localTimeText); }
private static bool CheckPowerToysLaunched() { bool isLaunched = false; trayButton.Click(); try { AppiumWebElement pt = PowerToysTrayButton(); isLaunched = (pt != null); } catch (OpenQA.Selenium.WebDriverException) { //PowerToys not found } trayButton.Click(); //close return(isLaunched); }
/// <summary> /// Move to and bring element to focus on screen using touch pointer. /// </summary> /// <param name="driver">driver</param> /// <param name="element">element to focus on</param> /// <param name="x">horizontal offset from origin</param> /// <param name="y">vertical offset from origin</param> public static void MoveTo(this AppiumDriver <AppiumWebElement> driver, AppiumWebElement element, int x, int y) { //ToDo: Make the scroll and tap work. Interact.PointerInputDevice inputDevice = new Interact.PointerInputDevice(PointerKind.Touch); ActionSequence actionSequence = new ActionSequence(inputDevice); actionSequence.AddAction(inputDevice.CreatePointerMove(element, x, y, TimeSpan.FromSeconds(1))); try { driver.PerformActions(new List <ActionSequence> { actionSequence }); } catch { TestContext.WriteLine($"Move to element: {element.Text} failed."); //ignore } finally { Wait.Seconds(0.5); } }
/// <summary> /// Initializes a new instance of the <see cref="OnboardingScreen"/> class. /// </summary> /// <param name="vpnSession">VPN session.</param> /// <param name="viewClassName">onboarding screen view class name.</param> public OnboardingScreen(WindowsDriver <WindowsElement> vpnSession, string viewClassName) { var onboardingView = vpnSession.FindElementByClassName(viewClassName); var textBlocks = onboardingView.FindElementsByClassName("TextBlock"); Assert.IsTrue(textBlocks.Count > 3); this.closeButton = vpnSession.FindElementByName("Close"); this.skip = textBlocks[0]; this.image = vpnSession.FindElementByClassName("Image"); this.title = textBlocks[1]; this.subtitle = textBlocks[2]; this.nextButton = vpnSession.FindElementByName("Next"); Assert.IsNotNull(this.closeButton); Assert.IsNotNull(this.skip); Assert.IsNotNull(this.image); Assert.IsNotNull(this.title); Assert.IsNotNull(this.subtitle); Assert.IsNotNull(this.nextButton); }
private AppiumWebElement ScrollUntillItemFound(AndroidDriver <AppiumWebElement> driver, AppiumWebElement relativeTo, Func <AppiumWebElement> FindElementAction, int reties) { var wait = new DefaultWait <AndroidDriver <AppiumWebElement> >(driver) { Timeout = TimeSpan.FromSeconds(60), PollingInterval = TimeSpan.FromMilliseconds(1000) }; wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); AppiumWebElement elementfound = null; elementfound = wait.Until(d => { Flick(driver, relativeTo, UpOrDown.Up); return(FindElementAction()); }); return(elementfound); }
public void TestChange() { string name = "TestChange"; string price = "213"; //We check if we have anything to change (suddenly the last test broke everything) AppiumWebElement listView = driver.FindElementByAccessibilityId("listBoxSelect"); IList <AppiumWebElement> items = listView.FindElementsByXPath(".//child::*"); List <string> texts = new List <string>(); foreach (AppiumWebElement item in items) { texts.Add(item.Text); } Assert.IsTrue(texts.Contains("1 musli 89"), "Don't repeat. No data."); /// We change item driver.FindElementByName("UPDATE").Click(); driver.FindElementByAccessibilityId("textBoxIdUpdate").SendKeys("1"); driver.FindElementByAccessibilityId("updateTextboxName").SendKeys(name); driver.FindElementByAccessibilityId("updateTextboxPrice").SendKeys(price); driver.FindElementByAccessibilityId("updateButton").Click(); //Go back and check that our changes have been accepted driver.FindElementByName("SELECT").Click(); listView = driver.FindElementByAccessibilityId("listBoxSelect"); listView.Click(); items = listView.FindElementsByXPath(".//child::*"); texts = new List <string>(); foreach (AppiumWebElement item in items) { texts.Add(item.Text); } Assert.IsTrue(texts.Contains("1 " + name + " " + price), "Item didn't change"); //Change the element back(what was done in the last test using the server side) driver.FindElementByName("UPDATE").Click(); driver.FindElementByAccessibilityId("textBoxIdUpdate").SendKeys("1"); driver.FindElementByAccessibilityId("updateTextboxName").SendKeys("musli"); driver.FindElementByAccessibilityId("updateTextboxPrice").SendKeys("89"); driver.FindElementByAccessibilityId("updateButton").Click(); }
// return mapping for second part of the article public static AppiumWebElement ArticleSecondPart(AndroidDriver <AppiumWebElement> driver) { String locator = "//android.widget.TextView[@index = 2]"; AppiumWebElement taboolaFeedButton = null; try { taboolaFeedButton = driver.FindElementByXPath(locator); } catch (Exception e) { // no need to throw an exception here /*throw new Exception("taboolaFeedButton not found, please check locator:" + Environment.NewLine + locator + Environment.NewLine + "original exception: " + e.Message);*/ } return(taboolaFeedButton); }
// return mapping for close adchoice public static AppiumWebElement CloseAdchoiceButton(AndroidDriver <AppiumWebElement> driver) { String locator = "//android.widget.ImageButton[contains(@resource-id , 'dismiss_button')]"; AppiumWebElement closeChoiceButton = null; try { // allow time for the content to be available Thread.Sleep(5000); closeChoiceButton = driver.FindElementByXPath(locator); } catch (Exception e) { throw new Exception("closeItemButton not found, please check locator:" + Environment.NewLine + locator + Environment.NewLine + "original exception: " + e.Message); } return(closeChoiceButton); }
// return mapping for "taboola feed" below the article public static AppiumWebElement TaboolaFeedLogo(AndroidDriver <AppiumWebElement> driver) { String locator = "//android.view.View[@resource-id = 'taboola']"; AppiumWebElement taboolaFeedButton = null; try { taboolaFeedButton = driver.FindElementByXPath(locator); } catch (Exception e) { // no need to throw an exception here /*throw new Exception("taboolaFeedButton not found, please check locator:" + Environment.NewLine + locator + Environment.NewLine + "original exception: " + e.Message);*/ } return(taboolaFeedButton); }
/// <summary> /// Delete one of other devices. /// </summary> /// <param name="desktopSession">Desktop session.</param> public void RandomDeleteOneDevice(WindowsDriver <WindowsElement> desktopSession) { var deviceListItems = this.deviceList.FindElementsByClassName("ListBoxItem"); int originalCount = deviceListItems.Count; if (originalCount > 1) { int randomIndex = Utils.RandomSelectIndex(Enumerable.Range(0, deviceListItems.Count), (i) => i != 0); AppiumWebElement randomDevice = deviceListItems[randomIndex]; AppiumWebElement deleteButton = randomDevice.FindElementByAccessibilityId("DeleteButton"); deleteButton.Click(); RemoveDevicePopup removeDevicePopup = new RemoveDevicePopup(desktopSession); Assert.AreEqual("Remove device?", removeDevicePopup.GetTitle()); Assert.IsTrue(removeDevicePopup.GetMessage().StartsWith("Please confirm you would like to remove")); removeDevicePopup.ClickRemoveButton(); int expectedDevices = originalCount - 1; int actualDevices = this.GetTotalNumberOfDevices(originalCount - 1); Assert.AreEqual(expectedDevices, actualDevices); } }
public void SpacingTestLargeValue() { Assert.IsTrue(OpenEditor()); editorWindow.FindElementByName("Grid").Click(); AppiumWebElement paddingValue = editorWindow.FindElementByAccessibilityId("paddingValue"); ClearText(paddingValue); paddingValue.SendKeys("1000"); editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); editorWindow = null; try { Assert.IsTrue(OpenEditor()); } catch { } Assert.AreNotEqual(editorWindow, null, "Editor Zones Window is not starting after setting large padding value"); }
/// <summary> /// Initializes a new instance of the <see cref="SettingScreen"/> class. /// </summary> /// <param name="vpnSession">VPN session.</param> public SettingScreen(WindowsDriver <WindowsElement> vpnSession) { this.vpnSession = vpnSession; var settingView = vpnSession.FindElementByClassName("SettingsView"); this.backButton = settingView.FindElementByName("Back"); this.titleText = settingView.FindElementByName("Settings"); this.signOutButton = settingView.FindElementByName("Sign out"); this.scrollDownButton = settingView.FindElementByAccessibilityId("PART_LineDownButton"); this.profileImage = settingView.FindElementByAccessibilityId("ProfileImageButton"); this.userName = settingView.FindElementByClassName("ScrollViewer").FindElementsByClassName("TextBlock")[1]; this.manageAccountButton = settingView.FindElementByName("Manage account"); this.launchVPNStartupCheckbox = settingView.FindElementByName("Launch VPN app on computer startup"); this.notificationButton = settingView.FindElementByAccessibilityId("NotificationsNavButton"); this.networkSettingButton = settingView.FindElementByAccessibilityId("NetworkSettingsNavButton"); this.languageButton = settingView.FindElementByAccessibilityId("LanguageNavButton"); this.aboutButton = settingView.FindElementByAccessibilityId("AboutNavButton"); this.helpButton = settingView.FindElementByAccessibilityId("GetHelpNavButton"); this.giveFeedbackText = settingView.FindElementByName("Give feedback"); this.giveFeedbackLinkButton = settingView.FindElementByName("Open link"); }
/// <summary> /// Initializes a new instance of the <see cref="AboutScreen"/> class. /// </summary> /// <param name="vpnSession">VPN session.</param> public AboutScreen(WindowsDriver <WindowsElement> vpnSession) { var aboutView = Utils.WaitUntilFindElement(vpnSession.FindElementByClassName, "AboutView"); this.backButton = Utils.WaitUntilFindElement(aboutView.FindElementByName, "Back"); this.title = Utils.WaitUntilFindElement(aboutView.FindElementByName, "About"); var textBlocks = Utils.WaitUntilFindElements(aboutView.FindElementsByClassName, "TextBlock"); this.fpnTitle = textBlocks[1]; this.fpnSubtitle = textBlocks[2]; this.releaseTitle = textBlocks[3]; this.releaseVersion = textBlocks[4]; this.termsOfService = Utils.WaitUntilFindElement(aboutView.FindElementByName, "Terms of Service"); this.termsOfServiceButton = Utils.WaitUntilFindElement(aboutView.FindElementByName, "Open Terms of Service link"); this.privacyPolicy = Utils.WaitUntilFindElement(aboutView.FindElementByName, "Privacy Policy"); this.privacyPolicyButton = Utils.WaitUntilFindElement(aboutView.FindElementByName, "Open Privacy Policy link"); this.debug = Utils.WaitUntilFindElement(aboutView.FindElementByName, "Debug"); this.debugButton = Utils.WaitUntilFindElement(aboutView.FindElementByName, "Open Debug link"); this.viewLog = Utils.WaitUntilFindElement(aboutView.FindElementByName, "View Log"); this.viewLogButton = Utils.WaitUntilFindElement(aboutView.FindElementByName, "Open View log link"); }
/// <summary> /// This method finds the element. Explicit wait time of 2 second is provided for this method to find the element. /// </summary> /// <returns>The element.</returns> /// <param name="bySelector">By selector.</param> public static AppiumWebElement FindElement(By bySelector) { DefaultWait <AppiumDriver <AppiumWebElement> > wait = new DefaultWait <AppiumDriver <AppiumWebElement> >(AppManager.CurrentAppDriver); AppiumWebElement elementFound = null; wait.PollingInterval = TimeSpan.FromMilliseconds(250); wait.Timeout = TimeSpan.FromSeconds(2); wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); try { elementFound = wait.Until((d) => { return(d.FindElement(bySelector)); }); } catch (Exception e) { PrintException(e); } return(elementFound); }