Appium Android Example On How To Scroll Down To Text

Earlier In THIS POST, nosotros learnt how to swipe In horizontal or vertical direction In whatever android software app using driver.swipe() in addition to swiping chemical cistron inwards horizontal direction using activity chain In previous post. Most of android applications comprise listing thought in addition to you lot necessitate to scroll down to conduct specific element. You tin use scrollTo(String text) method of IOSElement class If you lot wants to scroll downwards till specific text inwards appium software automation test. Let's endeavour to Implement It practically In android software appium automation examine to know how scrollTo(String text) method works.

PREREQUISITES : All previous 21 steps of appium mobile software app automation tutorials (PART 1 and PART 2) should live on completed.

Download And Install API Demos App
We volition use API Demos In this example. You tin download API Demos android software app from THIS PAGE. Install It In your mobile device.

Aim To Achieve In This Appium Test
We wants to scroll downwards till selected chemical cistron which contains text "Tabs" every bit shown In bellow Image. And in addition to thus nosotros wants to tap on It("Tabs" text). Manually you lot tin thought bellow given scroll-able listing inwards API Demos software App from API Demos App -> Views.


So In appium test,
  1. First nosotros volition opened upward API Demos App, 
  2. Tap on "Views".
  3. On side past times side screen, Scroll downwards till chemical cistron which comprise text "Tabs".
  4. And tap on chemical cistron which comprise text "Tabs". 
Create And Run Android Appium scrollTo Text Test
Create ScrollingToText.java file under Android parcel of your projection in addition to re-create glue bellow given examine script In It.

Note : Please gear upward your device's capabilities inwards bellow given test.
ScrollingToText.java
package Android;  import io.appium.java_client.android.AndroidDriver; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  world course of report ScrollingToText {  AndroidDriver driver;   @BeforeTest  world void setUp() throws Exception {   DesiredCapabilities capabilities = novel DesiredCapabilities();   capabilities.setCapability("deviceName", "ZX1B32FFXF");   capabilities.setCapability("browserName", "Android");   capabilities.setCapability("platformVersion", "4.4.2");   capabilities.setCapability("platformName", "Android");   capabilities.setCapability("appPackage", "io.appium.android.apis");   capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");   driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  }   @Test  world void ScrollToText() throws InterruptedException {   //Scroll till chemical cistron which contains "Views" text If It Is non visible on screen.   driver.scrollTo("Views");   // Click on Views/.   driver.findElement(By.name("Views")).click();   System.out.println("Scrolling has been started to expose text -> Tabs.");   // Scroll till chemical cistron which contains Tabs text.   driver.scrollTo("Tabs");   System.out.println("Tabs text has been institute in addition to at ane time clicking on It.");   // Click on Tabs.   driver.findElement(By.name("Tabs")).click();  }   @AfterTest  world void End() {   driver.quit();  } }

Test Script Description
If you lot await at higher upward examine example, We convey used driver.scrollTo(String text) methods for scrolling. It volition scroll downwards steps past times stride in addition to await If given text Is displayed on hide or not. When text appears, It volition halt scrolling.
  • First driver.scrollTo("Views"); volition cheque if chemical cistron containing examine "Views" Is display on hide or not. If non display in addition to thus It volition scroll downwards down in addition to cheque for text ane time again.
  • Same way, Second driver.scrollTo("Tabs"); volition scroll downwards in addition to cheque for text "Tabs".
To encounter scrollToText demo practically, Run higher upward examine using testng in addition to appium in addition to notice effect on your android mobile screen.

This agency you lot tin scroll downwards vertically to expose specific chemical cistron in addition to click on It.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post