Earlier inwards THIS POST, We learnt different chemical gene locators of android app similar XPath, ID, Name And className to role inwards appium automation exam script. We likewise learnt android application's chemical gene locating strategy using findElements method of webdriver. I convey prepared really elementary appium android app test of existent android mobile device's calculator application where I convey used all inwards a higher house element locating strategies hence that you lot tin hand notice understand android app chemical gene locators better.
PREREQUISITES : Appium android tutorial articles 1 TO 15 as well as 16 TO 17 should hold upwards completed.
After reading all previous appium tutorials, I promise you lot convey plenty noesis on how to operate appium exam on existent android device or emulator. Now let's Implement appium android exam as well as sympathize how to role dissimilar chemical gene locators inwards android appium automation test. Follow steps given bellow.
1. Connect your android device alongside PC and start USB debugging mode. View THIS POST.
2. Launch as well as kickoff appium server. View THIS POST.
3. Install TestNG inwards eclipse if it is non installed. View THIS POST.
3. Install TestNG inwards eclipse if it is non installed. View THIS POST.
4. Create bellow given appium android exam script nether Android packet of your projection inwards eclipse.
ElementLocatorTest.java
package Android; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; populace course of report ElementLocatorTest { WebDriver driver; @BeforeTest populace void setUp() throws MalformedURLException { // Created object of DesiredCapabilities class. DesiredCapabilities capabilities = novel DesiredCapabilities(); // Set android deviceName desired capability. Set your device name. capabilities.setCapability("deviceName", "ZX1B32FFXF"); // Set BROWSER_NAME desired capability. It's Android inwards our representative here. capabilities.setCapability("browserName", "Android"); // Set android VERSION desired capability. Set your mobile device's OS version. capabilities.setCapability("platformVersion", "4.4.2"); // Set android platformName desired capability. It's Android inwards our representative here. capabilities.setCapability("platformName", "Android"); // Set android appPackage desired capability. It is com.android.calculator2 for figurer application. // Set your application's appPackage if you lot are using whatsoever other app. capabilities.setCapability("appPackage", "com.android.calculator2"); // Set android appActivity desired capability. It is com.android.calculator2.Calculator for figurer application. // Set your application's appPackage if you lot are using whatsoever other app. capabilities.setCapability("appActivity", "com.android.calculator2.Calculator"); // Created object of RemoteWebDriver volition all laid capabilities. // Set appium server address as well as port number inwards URL string. // It volition launch figurer app inwards android device. driver = novel RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); } @Test populace void Sum() { // Using findElements. // Locate DELETE/CLR push using findElements as well as get() method as well as click on it. driver.findElements(By.xpath("//android.widget.Button")).get(0).click(); // By xpath. // Locate number push 2 yesteryear XPATH chemical gene locator as well as click on it. driver.findElement(By.xpath("//android.widget.Button[@text='2']")).click(); // Using findElements. // Locate number push + using findElements as well as get() method as well as click on it. driver.findElements(By.xpath("//android.widget.Button")).get(16).click(); // By id. // Locate number push five yesteryear ID chemical gene locator as well as click on it. driver.findElement(By.id("com.android.calculator2:id/digit5")).click(); // By name. // Locate number push = yesteryear mention chemical gene locator as well as click on it. driver.findElement(By.name("=")).click(); // By className. // Locate number textbox yesteryear CLASSNAME chemical gene locator as well as buy the farm number from it. String number = driver.findElement(By.className("android.widget.EditText")).getText(); System.out.println("Number amount number is : " + result); } @AfterTest populace void End() { //Quit driver.quit(); } }
Each as well as every chemical gene locator is already explained inwards comment alongside exam script's each statement. You tin hand notice run across inwards in a higher house script, I convey used all dissimilar chemical gene locators to locate dissimilar elements of android figurer app.
- findElements with get() method : findElements with get() method chemical gene locating strategy is used to locate DELETE as well as + buttons of calc app. Here "android.widget.Button" is mutual class name of all buttons. So It volition discovery all elements which contains course of report mention = "android.widget.Button" as well as hence get() method volition locate given Indexed chemical gene from list. DELETE push has index = 0 and + push has index = 16.
- xpath : xpath chemical gene locator is used to locate number push 2. Here "android.widget.Button" is course of report mention as well as hence it volition hold off for chemical gene where text value = "2".
- id : id chemical gene locator is used to locate number push 5. Here it volition involve hold off for chemical gene where resource-id="com.android.calculator2:id/digit5".
- name : mention chemical gene locator is used to locate = button. In this case, It volition hold off for chemical gene where text value = "=".
- className : className element locator is used to locate number text area. It volition discovery chemical gene where class value = "android.widget.EditText".
I hope, this is plenty to sympathize android app chemical gene locators. You tin hand notice role all inwards a higher house described chemical gene locators for whatsoever application.
Now you lot tin hand notice operate inwards a higher house appium android exam script using testng(Right click on exam representative -> Run As -> TestNG Test) inwards eclipse. It volition impress number ii number's amount number inwards console.