public void FindElementById(string element) { var duration = new Stopwatch(); var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(TestConstants.Wait)); try { Thread.Sleep(TestConstants.PageLoadTime); duration.Start(); var result = wait.Until(d => _driver.FindElementByAccessibilityId(element)); if (result != null && result.Enabled) { result.Click(); Assert.IsNotNull(result); } else { Log.Error(TestConstants.ElementNotFound + element); } duration.Stop(); Log.Info(MethodBase.GetCurrentMethod().Name + "(" + element + ")" + TestConstants.Sp + duration.ElapsedMilliseconds + TestConstants.Ms); } catch (Exception e) { Log.Error(TestConstants.ElementNotFound + element + e); throw new ElementNotVisibleException(TestConstants.ElementNotFound + element + e); } }
public void TradeMe_verify_logged_in() { // Find the login input field AppiumWebElement TradeMe_Login = app.FindElementById("nz.co.trademe.trademe:id/editTextLoginEmail"); // key in your user name TradeMe_Login.SendKeys("*****@*****.**"); // Find the password field AppiumWebElement TradeMe_Pwd = app.FindElementById("nz.co.trademe.trademe:id/editTextLoginPassword"); // key in the password TradeMe_Pwd.SendKeys("yorks64"); // Find the login button AppiumWebElement Login_Button = app.FindElementById("nz.co.trademe.trademe:id/buttonLogin"); // Tap the login button Login_Button.Tap(1, 1); // Wait for the account menu item to be displayed WebDriverWait wait = new WebDriverWait(app, TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("nz.co.trademe.trademe:id/menuAccount"))); // Find icon for my account AppiumWebElement account_icon = app.FindElementByAccessibilityId("Account"); // tap the icon account_icon.Tap(1, 1); // confirm that the logout button is visible, this is in turn ensure that the user name isbeing displayed wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("nz.co.trademe.trademe:id/buttonLogout"))); // find and assert on the text of the user name AppiumWebElement account_name = app.FindElementById("nz.co.trademe.trademe:id/textViewAboutMemberUsername"); Assert.AreEqual(account_name.Text, "sunjeet81"); }
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']")); }
public void TradeMe_verify_logged_account() { AppiumWebElement TradeMe_Login = app.FindElementById("nz.co.trademe.trademe:id/editTextLoginEmail"); Assert.IsNotNull(TradeMe_Login); TradeMe_Login.SendKeys("*****@*****.**"); AppiumWebElement TradeMe_Pwd = app.FindElementById("nz.co.trademe.trademe:id/editTextLoginPassword"); TradeMe_Pwd.SendKeys("yorks64"); AppiumWebElement Login_Button = app.FindElementById("nz.co.trademe.trademe:id/buttonLogin"); Login_Button.Tap(1, 1); WebDriverWait wait = new WebDriverWait(app, TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("nz.co.trademe.trademe:id/menuAccount"))); AppiumWebElement account_icon = app.FindElementByAccessibilityId("Account"); account_icon.Tap(1, 1); WebDriverWait wait1 = new WebDriverWait(app, TimeSpan.FromSeconds(30)); wait1.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("nz.co.trademe.trademe:id/buttonLogout"))); AppiumWebElement account_name = app.FindElementById("nz.co.trademe.trademe:id/textViewAboutMemberUsername"); Assert.AreEqual(account_name.Text, "sunjeet81"); AppiumWebElement logout_button = app.FindElementById("nz.co.trademe.trademe:id/buttonLogout"); logout_button.Tap(1, 1); WebDriverWait wait2 = new WebDriverWait(app, TimeSpan.FromSeconds(30)); wait2.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("nz.co.trademe.trademe:id/buttonDialogGenericConfirm"))); AppiumWebElement confirm_button = app.FindElementByAccessibilityId("Confirm"); confirm_button.Tap(1, 1); Assert.IsNotNull(app.FindElementByAccessibilityId("Login")); }
public void ScrollingToSubElement() { _driver.FindElementByAccessibilityId("Views").Click(); var list = _driver.FindElement(By.Id("android:id/list")); var locator = new ByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(" + "new UiSelector().text(\"Radio Group\"));"); var radioGroup = list.FindElement(locator); Assert.NotNull(radioGroup.Location); }
public void TestThatUserCanSignInWithFacebookFromStatus() { SelectBeverage(); FacebookLogin(); Thread.Sleep(2000); // Check If On Beverage Select screen // The search bar only Beverage Select screen AndroidElement element = driver.FindElementByAccessibilityId("StatusPage"); // If the element is displayed, we are on the Beverage Select screen Assert.IsTrue(element.Displayed); }
public void StaticAllocation() { /* * By default, every time you complete a test session, * the real device cloud uninstalls your application, * performs device cleaning, and de-allocates the device. * This means that if you have multiple tests that you want to run on the same device, * you will, by default, * wait for this cleaning process to complete between every test. */ //capabilities.SetCapability("platformName", "*"); //capabilities.SetCapability("platformVersion", "*"); var capabilities = new DesiredCapabilities(); capabilities.SetCapability("deviceName", "Asus_Google_Nexus_7_2013_real"); capabilities.SetCapability("testobject_api_key", VodQANativeAppApiKey); capabilities.SetCapability("name", MethodBase.GetCurrentMethod().Name); capabilities.SetCapability("newCommandTimeout", 90); _driver = new AndroidDriver <IWebElement>(new Uri(USurl), capabilities, TimeSpan.FromSeconds(300)); _sessionId = _driver.SessionId; //var usernameField = _driver.FindElementByAccessibilityId("username"); //var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(20)); //var isVisible = wait.Until(ExpectedConditions.ElementIsVisible(By)) Assert.IsTrue(_driver.FindElementByAccessibilityId("username").Displayed); }
public void Test1() { var xp2 = "//*[@text='Log in']"; var xp = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[3]/android.widget.TextView"; //AndroidElement confirmAndContinue = _driver.FindElementByXPath("//*[@resource-id='com.example.android.apis:id/button']"); AndroidElement button = _driver.FindElementByXPath(xp); button.Click(); AndroidElement button2 = _driver.FindElementByXPath(xp2); button2.Click(); AndroidElement el3 = _driver.FindElementByAccessibilityId("Yes"); el3.Click(); AndroidElement el4 = _driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.ImageView"); el4.Click(); var journey = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[3]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[16]/android.view.ViewGroup[2]/android.widget.TextView"; AndroidElement el5 = _driver.FindElementByXPath(journey); el5.Click(); System.Threading.Thread.Sleep(20000); Assert.Pass(); }
public void deveSomarDoisValores() { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.SetCapability("platformName", "Android"); desiredCapabilities.SetCapability("deviceName", "emulator-5554"); desiredCapabilities.SetCapability("automationName", "uiautomator2"); desiredCapabilities.SetCapability("appPackage", "com.android.calculator2"); desiredCapabilities.SetCapability("appActivity", "com.android.calculator2.Calculator"); AndroidDriver <AppiumWebElement> driver = new AndroidDriver <AppiumWebElement>(new Uri("http://localhost:4723/wd/hub"), desiredCapabilities); AppiumWebElement el3 = (AppiumWebElement)driver.FindElementById("com.android.calculator2:id/digit_2"); el3.Click(); AppiumWebElement el4 = (AppiumWebElement)driver.FindElementByAccessibilityId("plus"); el4.Click(); AppiumWebElement el5 = (AppiumWebElement)driver.FindElementById("com.android.calculator2:id/digit_2"); el5.Click(); AppiumWebElement el6 = (AppiumWebElement)driver.FindElementById("com.android.calculator2:id/result"); //System.out.print(el6.Text); Assert.AreEqual("4", el6.Text); driver.Quit(); }
public void deveSomarDoisValoress() { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.SetCapability("platformName", "Android"); desiredCapabilities.SetCapability("deviceName", "0030260344"); desiredCapabilities.SetCapability("automationName", "uiautomator2"); desiredCapabilities.SetCapability("appPackage", "com.google.android.calculator"); desiredCapabilities.SetCapability("appActivity", "com.android.calculator2.CalculatorGoogle"); AndroidDriver <AppiumWebElement> driver = new AndroidDriver <AppiumWebElement>(new Uri("http://localhost:4723/wd/hub"), desiredCapabilities); AppiumWebElement el1 = (AppiumWebElement)driver.FindElementById("com.google.android.calculator:id/digit_4"); el1.Click(); el1.Click(); AppiumWebElement el2 = (AppiumWebElement)driver.FindElementByAccessibilityId("mais"); el2.Click(); AppiumWebElement el3 = (AppiumWebElement)driver.FindElementById("com.google.android.calculator:id/digit_4"); el3.Click(); AppiumWebElement el4 = (AppiumWebElement)driver.FindElementById("com.google.android.calculator:id/result"); Assert.AreEqual("8", el4.Text); driver.Quit(); }
public AppiumWebElement Create_a_NewNote() { AppiumWebElement new_note = driver.FindElementByAccessibilityId("New note"); new_note.Tap(1, 1); AppiumWebElement new_note_screen = driver.FindElementById("android:id/action_bar_title"); return(new_note_screen); }
public static async Task WaitForNoElementByAccessibilityId(this AndroidDriver <AndroidElement> driver, String selector, TimeSpan?timeout = null) { timeout ??= TimeSpan.FromSeconds(60); await Retry.For(async() => { var element = driver.FindElementByAccessibilityId(selector); element.ShouldNotBeNull($"Element {selector} is not null but should be"); }); }
public void FindScrollable() { _driver.FindElementByAccessibilityId("Views").Click(); var radioGroup = _driver .FindElementByAndroidUIAutomator("new UiScrollable(new UiSelector()" + ".resourceId(\"android:id/list\")).scrollIntoView(" + "new UiSelector().text(\"Radio Group\"));"); Assert.NotNull(radioGroup.Location); }
public void AddTest() { AppiumWebElement el4 = (AppiumWebElement)driver.FindElementByAccessibilityId("Add"); el4.Click(); AppiumWebElement el5 = (AppiumWebElement)driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup[1]/android.support.v4.view.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ListView/android.widget.LinearLayout[1]/android.view.ViewGroup/android.view.ViewGroup"); el5.Click(); el5.Clear(); el5.SendKeys("New item"); AppiumWebElement el6 = (AppiumWebElement)driver.FindElementByAccessibilityId("Save"); el6.Click(); AppiumWebElement el7 = (AppiumWebElement)driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ListView/android.widget.LinearLayout[7]/android.view.ViewGroup/android.view.ViewGroup"); el7.Click(); AppiumWebElement el8 = (AppiumWebElement)driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.TextView"); AppiumWebElement el9 = (AppiumWebElement)driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.widget.ImageButton"); el9.Click(); Assert.IsTrue(el8.Text.Equals("New item")); }
public void SearchTest() { int duration = 1000; string text_to_search = "RDA"; Thread.Sleep(duration); AndroidElement searchMenuButton = driver.FindElementById("com.alibaba.aliexpresshd:id/search_hint"); searchMenuButton.Click(); AndroidElement searchField = driver.FindElementByAccessibilityId("Поисковый запрос"); searchField.SendKeys(text_to_search); searchField.Click(); driver.PressKeyCode(AndroidKeyCode.Enter); wait.Until(ExpectedConditions.ElementExists(By.Id("com.alibaba.aliexpresshd:id/search_result_list"))); }
private AndroidElement FindByResourceID(string resourceID) { return(driver.FindElementByAccessibilityId(resourceID)); }
public AndroidElement GetElementByAccessibilityID(string id) { return(driver.FindElementByAccessibilityId(id)); }
public void AddNewItemWithNewCategory() { System.Environment.SetEnvironmentVariable("ANDROID_HOME", @"C:\Program Files (x86)\Android\android-sdk"); System.Environment.SetEnvironmentVariable("JAVA_HOME", @"C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin"); var capabilities = new AppiumOptions(); // automatic start of the emulator if not running capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.Avd, "demo_device"); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AvdArgs, "-no-boot-anim -no-snapshot-load"); capabilities.AddAdditionalCapability(MobileCapabilityType.FullReset, true); // connecting to a device or emulator capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "2471736c36037ece"); capabilities.AddAdditionalCapability(MobileCapabilityType.AutomationName, "UiAutomator2"); // specifyig which app we want to install and launch var currentPath = Directory.GetCurrentDirectory(); Console.WriteLine($"Current path: {currentPath}"); var packagePath = Path.Combine(currentPath, @"..\..\..\AppsToTest\com.fluentbytes.carvedrock-x86.apk"); packagePath = Path.GetFullPath(packagePath); Console.WriteLine($"Package path: {packagePath}"); capabilities.AddAdditionalCapability(MobileCapabilityType.App, packagePath); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AppPackage, "com.fluentbytes.carvedrock"); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AppActivity, "crc641782d5af3c9cf50a.MainActivity"); var _appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort().Build(); _appiumLocalService.Start();; var driver = new AndroidDriver <AppiumWebElement>(_appiumLocalService, capabilities); // Create new Category item first var categoryButton = driver.FindElement(MobileBy.AccessibilityId("AddCategory")); categoryButton.Click(); // fill out the form for a new category var categoryName = driver.FindElement(MobileBy.AccessibilityId("categoryName")); categoryName.Clear(); categoryName.SendKeys("New category from automation"); //save category var saveCategory = driver.FindElement(MobileBy.AccessibilityId("Save")); saveCategory.Click(); var el1 = driver.FindElementByAccessibilityId("Add"); el1.Click(); var elItemText = driver.FindElementByAccessibilityId("ItemText"); elItemText.Clear(); elItemText.SendKeys("This is a new Item"); var elItemDetail = driver.FindElementByAccessibilityId("ItemDescription"); elItemDetail.Clear(); elItemDetail.SendKeys("These are the details"); var elItemCategory = driver.FindElement(MobileBy.AccessibilityId("ItemCategory_Container")); elItemCategory.Click(); var picker = driver.FindElement(By.Id("android:id/contentPanel")); var categoryListItems = picker.FindElements(By.ClassName("android.widget.TextView")); foreach (var categoryElement in categoryListItems) { if (categoryElement.Text == "New category from automation") { categoryElement.Click(); } } var elSave = driver.FindElementByAccessibilityId("Save"); elSave.Click(); //wait for progress bar to disapear var wait = new DefaultWait <AndroidDriver <AppiumWebElement> >(driver) { Timeout = TimeSpan.FromSeconds(60), PollingInterval = TimeSpan.FromMilliseconds(500) }; wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); wait.Until(d => d.FindElement(MobileBy.AccessibilityId("Second item"))); var listview = driver.FindElementByAccessibilityId("ItemsListView"); //now use wait to scroll untill we find item Func <AppiumWebElement> FindElementAction = () => { // find all text views // check if the text matches var elements = driver.FindElementsByClassName("android.widget.TextView"); foreach (var textView in elements) { if (textView.Text == "This is a new Item") { return(textView); } } return(null); }; 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 => { var input = new PointerInputDevice(PointerKind.Touch); ActionSequence FlickUp = new ActionSequence(input); FlickUp.AddAction(input.CreatePointerMove(listview, 0, 0, TimeSpan.Zero)); FlickUp.AddAction(input.CreatePointerDown(MouseButton.Left)); FlickUp.AddAction(input.CreatePointerMove(listview, 0, -600, TimeSpan.FromMilliseconds(200))); FlickUp.AddAction(input.CreatePointerUp(MouseButton.Left)); driver.PerformActions(new List <ActionSequence>() { FlickUp }); return(FindElementAction()); }); Assert.IsTrue(elementfound != null); driver.CloseApp(); }