Appium - How To Scroll Horizontal Tabs Using Appium In Android App

In android appium software automation test, You also needs to scroll tabs horizontally(from correct to left or left to right) If in that place are multiple tabs In your android software app as well as y'all wants to navigate to the tab which Is displaying when y'all scroll tabs horizontally. Earlier In my previous post, We learnt how to scroll down In android software app using appium test. We also learnt how to swipe In android software app using driver.swipe() In THIS POST as well as using TouchAction bird In THIS POST. Here nosotros tin sack purpose driver.swipe() method to swipe tabs from correct to left. I bring prepared really uncomplicated android software automation illustration to acquire how to swipe android app's tabs In appium automation test.

Install API Demos App In Mobile Device
You tin sack persuasion my PREVIOUS POST to know from where to download API Demos App. Install It In your mobile device.

Aim To Achieve In This Appium Test
In this test, We wants to scroll tabs horizontally from correct to left side until Tab 11 display every bit shown inwards bellow Image.


Manually y'all tin sack persuasion higher upwardly given concealment In your mobile device from API Demos App -> Views -> Tabs -> 5. Scrollable. You volition uncovering that transcend bird tabs are scroll-able.

Before learning tabs scrolling In appium software automation test, I recommend y'all to read my previous transportation service virtually vertical scrolling In appium examination every bit nosotros are going to purpose vertical scrolling inwards this illustration too.

Get Y Coordinates Of Tabs Grid Middle
To acquire Y Coordinates of tabs grid,
  1. Connect your mobile device alongside PC as well as opened upwardly API Demos app In your device.
  2. Navigate manually to 5. Scrollable department every bit described above.
  3. Open uiautomatorviewer from tools folder of SDK. persuasion THIS POST.
  4. Capture Screenshot yesteryear clicking on Capture screenshot button.
  5. Move your mouse at middle of tabs grid.
  6. Note downwards Y Coordinates every bit shown In bellow Image.

Create And Run Android Appium Tabs Scrolling Test
Create new ScrollTabs.java file nether your projection as well as re-create glue bellow given examination script In It.

Note : Please laid your device's capabilities inwards bellow given test.
ScrollTabs.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.Dimension; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  world bird ScrollTabs {  AndroidDriver driver;  Dimension size;  @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 ScrollToTab() throws InterruptedException {   //Scroll till chemical component 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("Vertical scrolling has been started to uncovering text -> Tabs.");   //Scroll till chemical component which contains "Tabs" text.   driver.scrollTo("Tabs");   System.out.println("Tabs text has been works life as well as similar a shot clicking on It.");   //Click on Tabs   driver.findElement(By.name("Tabs")).click();   //Click on Scrollable text element.   driver.findElement(By.name("5. Scrollable")).click();   System.out.println("Horizontal scrolling has been started to uncovering tab -> Tab 11.");   //Used for loop to scroll tabs until Tab xi displayed.   for(int i=0; i<=10; i++){    //Set implicit expect to two seconds for fast horizontal scrolling.    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);       if(driver.findElements(By.name("Tab 11")).size()!= 0){     //If Tab xi Is displayed as well as therefore click on It.     System.out.println("Tab xi has been works life as well as similar a shot clicking on It.");     driver.findElement(By.name("Tab 11")).click();     break;    }else{     //If Tab xi Is non displayed as well as therefore scroll tabs from correct to left management yesteryear calling ScrollTabs() method.     ScrollTabs();    }   }   //Set implicit expect to xv seconds afterward horizontal scrolling.   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);      //Locate raise chemical component of text area.   WebElement ele1 = (WebElement) driver.findElements(By.id("android:id/tabcontent")).get(0);   //Locate text surface area of Tab xi using It's raise element.   WebElement ele2 = ele1.findElement(By.className("android.widget.TextView"));   //Get text from text surface area of Tab xi as well as impress It In console.   System.out.println("Text nether selected tab is -> "+ele2.getText());  }     //To scroll tabs correct to left In horizontal direction.  world void ScrollTabs() {   //Get the size of screen.   size = driver.manage().window().getSize();        //Find swipe get-go as well as halt indicate from screen's alongside as well as height.   //Find startx indicate which is at correct side of screen.   int startx = (int) (size.width * 0.70);   //Find endx indicate which is at left side of screen.   int endx = (int) (size.width * 0.30);   //Set Y Coordinates of concealment where tabs display.   int YCoordinates = 150;      //Swipe tabs from Right to Left.   driver.swipe(startx, YCoordinates, endx, YCoordinates, 3000);    }    @AfterTest  world void End() {   driver.quit();  } }

Test Script Description
In higher upwardly examination script, 
  • I bring used for loop to expire along execution until Tab xi display on screen.
  • If status Inside for loop volition banking enterprise tally If Tab xi Is displayed or not.
  • If tab xi Is displayed as well as therefore click on It as well as interruption the loop.
  • Else Call ScrollTabs(); method which Is responsible for swiping tab from correct to left.
  • Statements written bellow for loop volition acquire text from  text surface area as well as impress It In console.
Now I hope, You already learnt how to run appium software automation examination In eclipse alongside testng. View my previous appium tutorials for to a greater extent than detail. When y'all run higher upwardly test, It volition Navigate to 5. Scrollable concealment as well as and therefore scroll tabs In horizontal management until Tab xi displayed.

This agency y'all tin sack scroll tabs inwards horizontal management In your appium android test.


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