// Get a list of elements from selector and return based on index public static AndroidElement GetElementFromList(AndroidDriver <AndroidElement> driver, SelectBy by, string selector, int index) { AndroidElement e = null; switch (by) { case SelectBy.ID: e = driver.FindElementsById(selector)[index]; break; case SelectBy.Class: e = driver.FindElementsByClassName(selector)[index]; break; case SelectBy.XPath: e = driver.FindElementsByXPath(selector)[index]; break; case SelectBy.ExactText: e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().text(\"{0}\")", selector)).ElementAt(index); break; case SelectBy.ContainsText: e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().textContains(\"{0}\")", selector)).ElementAt(index); break; case SelectBy.RegexText: e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().textMatches(\"{0}\")", selector)).ElementAt(index); break; } return(e ?? throw new NotFoundException("Element with selector " + selector + " not found.")); }
public void FindElementTestCase() { By byAccessibilityId = new ByAccessibilityId("Graphics"); Assert.AreNotEqual(driver.FindElement(byAccessibilityId).Text, null); Assert.GreaterOrEqual(driver.FindElements(byAccessibilityId).Count, 1); driver.FindElementByAccessibilityId("Graphics").Click(); Assert.IsNotNull(driver.FindElementByAccessibilityId("Arcs")); driver.Navigate().Back(); Assert.IsNotNull(driver.FindElementByName("App")); Assert.IsNotNull(driver.FindElement(new ByAndroidUIAutomator("new UiSelector().clickable(true)")).Text); var els = driver.FindElementsByAndroidUIAutomator("new UiSelector().clickable(true)"); Assert.GreaterOrEqual(els.Count, 12); var els2 = driver.FindElements(new ByAndroidUIAutomator("new UiSelector().enabled(true)")); Assert.GreaterOrEqual(els2.Count, 20); els = driver.FindElementsByAndroidUIAutomator("new UiSelector().enabled(true)"); Assert.GreaterOrEqual(els.Count, 20); Assert.IsNotNull(driver.FindElementByXPath("//android.widget.TextView[@text='API Demos']")); }
internal protected bool HasContentDesc(string label, CompareType compareType, int timeoutSecs) { IList <IWebElement> texts; switch (compareType) { case CompareType.Equals: texts = Driver.FindElementsByAndroidUIAutomator(@"new UiSelector().description(""" + label + @""")", timeoutSecs); break; case CompareType.StartsWith: texts = Driver.FindElementsByAndroidUIAutomator(@"new UiSelector().descriptionStartsWith(""" + label + @""")", timeoutSecs); break; case CompareType.Matching: texts = Driver.FindElementsByAndroidUIAutomator(@"new UiSelector().descriptionMatches(""" + label + @""")", timeoutSecs); break; case CompareType.Containing: texts = Driver.FindElementsByAndroidUIAutomator(@"new UiSelector().descriptionContains(""" + label + @""")", timeoutSecs); break; default: throw new NotImplementedException("Not implemented compare type: " + compareType); } return(texts != null && texts.Count != 0); }
public void FindElementsByAndroidUIAutomatorTestCase() { AndroidDriver <IWebElement> driver = new AndroidDriver <IWebElement>(defaultUri, capabilities); List <object> results = new List <object>(); results.Add(new Dictionary <string, object> { { "ELEMENT", "4" } }); results.Add(new Dictionary <string, object> { { "ELEMENT", "6" } }); results.Add(new Dictionary <string, object> { { "ELEMENT", "8" } }); server.respondTo("POST", "/elements", results); ICollection <IWebElement> elements = driver.FindElementsByAndroidUIAutomator(".elements()"); Assert.AreEqual(elements.Count, 3); }
public void FindElementTestCase() { driver.FindElementByXPath("//android.widget.TextView[@text='Animation']"); Assert.AreEqual(driver.FindElementByXPath("//android.widget.TextView").Text, "API Demos"); IList <AppiumWebElement> els = driver.FindElementsByXPath("//android.widget.TextView[contains(@text, 'Animat')]"); var elsres = Filters.FilterDisplayed <AppiumWebElement>(els); if (!Env.isSauce()) { Assert.AreEqual(elsres [0].Text, "Animation"); } driver.FindElementByName("App").Click(); Thread.Sleep(3000); els = driver.FindElementsByAndroidUIAutomator("new UiSelector().clickable(true)"); Assert.GreaterOrEqual(els.Count, 10); Assert.IsNotNull( driver.FindElementByXPath("//android.widget.TextView[@text='Action Bar']")); els = driver.FindElementsByXPath("//android.widget.TextView"); elsres = Filters.FilterDisplayed <AppiumWebElement>(els); Assert.AreEqual(elsres[0].Text, "API Demos"); driver.Navigate().Back(); }
public override IEnumerable <AndroidElement> FindAllElements(AndroidDriver <AndroidElement> searchContext) { return(searchContext.FindElementsByAndroidUIAutomator(_locatorValue)); }
public override IEnumerable <AndroidElement> FindAllElements(AndroidDriver <AndroidElement> searchContext) => searchContext.FindElementsByAndroidUIAutomator(Value);
static void Main(string[] args) { // AppiumOptions opt = new AppiumOptions(); // opt.AddAdditionalCapability("deviceName", "emulator-5554"); // opt.AddAdditionalCapability("platformName", "Android"); // // opt.AddAdditionalCapability("browserName", "chrome"); // opt.AddAdditionalCapability("udid", "emulator-5554"); // opt.AddAdditionalCapability("app", @"E:\DHLe-MobileV0.1.6.apk"); //// opt.AddAdditionalCapability("automationName", "UIAutomator2"); // AndroidDriver<IWebElement> driver = // new AndroidDriver<IWebElement>(new Uri("http://*****:*****@"E:\DHLe-MobileV0.1.6.apk"); opt.AddAdditionalCapability("automationName", "UIAutomator2"); opt.AddAdditionalCapability("appPackage", "org.khanacademy.android"); opt.AddAdditionalCapability("appActivity", "org.khanacademy.android.ui.library.MainActivity"); opt.AddAdditionalCapability("noReset", true); driver = new AndroidDriver <IWebElement>(new Uri("http://localhost:4723/wd/hub"), opt); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); if (driver.FindElementsByAndroidUIAutomator("UiSelector().text(\"Dismiss\")").Count > 0) { driver.FindElementByAndroidUIAutomator("UiSelector().text(\"Dismiss\")").Click(); } driver.FindElementById("org.khanacademy.android:id/tab_bar_button_profile").Click(); driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"Sign up\")").Click(); driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"Birth\")").Click(); ReadOnlyCollection <IWebElement> dateEle = driver.FindElementsById("android:id/numberpicker_input"); //foreach(IWebElement ele in dateEle) //{ // Console.WriteLine(ele.Text); //} dateEle[0].Click(); dateEle[0].Clear(); dateEle[0].SendKeys("Aug"); driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"OK\")").Click(); driver.FindElementByAndroidUIAutomator("UiSelector().text(\"Home\")").Click(); Size size = driver.Manage().Window.Size; int width = size.Width; int height = size.Height; while (driver.FindElementsByAndroidUIAutomator("UiSelector().textContains(\"College\")").Count == 0) { //scroll TouchAction action = new TouchAction(driver); //action.Tap(100, 500, 6).Perform(); //action.Press(width / 2, 3 * height / 4).MoveTo(width / 2, height / 4).Release().Perform(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("command", "input touchscreen swipe 250 800 250 400"); driver.ExecuteScript("mobile:shell", dic); } driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"College\")").Click(); //IWebDriver d = new ChromeDriver(); //ITakesScreenshot ts = (ITakesScreenshot)d; //ts.GetScreenshot().SaveAsFile("Error.png"); ; } catch (Exception e) { Console.WriteLine(e.Message); // string path = Directory.GetParent(Directory.GetCurrentDirectory()).Name; driver.GetScreenshot().SaveAsFile("Error.png"); } }