Appium - How To Swipe Vertical And Horizontal In Android Automation

Earlier In previous post, nosotros learnt how to interact amongst android mobile gesture to perform drag in addition to drib past times generating activity chain using TouchAction degree of Webdriver 3. Swiping is unopen to other mutual activity for whatever android mobile app. As you lot know, We tin swipe horizontally(left to correct or correct to left) and swipe vertically(bottom to grade off in addition to grade off to bottom) In android mobile app. Here I accept described how to swipe horizontally in addition to vertically In android mobile app using driver.swipe() when running appium automation test. Follow me throughout this article to learn how to swipe inwards android app using appium.

PREREQUISITES : Previous nineteen steps(PART 1 in addition to PART 2) of appium tutorials should hold out completed.

Download And Install SwipeListView Demo App
We volition piece of employment SwipeListView Demo App for android swipe examination using appium. You withdraw to download in addition to install SwipeListView Demo App inwards your android mobile device.
  • You tin THIS PAGE.
  • Install it inwards your android mobile device.
  • Open SwipeListView Demo App In your mobile device. It volition present you lot alarm message on screen.
  • Select "Don't present this message again" banking concern fit box in addition to click on OK push every bit shown inwards bellow image. Now this message volition non display in 1 trial again when nosotros run our examination through appium.

  • It volition present you lot listing of apps inwards your android device. Using this app, You tin swipe horizontal in addition to vertical.
Aim To Achieve In This Appium Test
I accept a two goals to arrive at from this postal service in appium. 1. Horizontal swiping and 2. Vertical swiping inwards android app.

1. Horizontal Swiping In Android App
Using appium, We wants to swipe correct to left in addition to left to correct horizontally every bit shown inwards bellow Image.


2. Vertical Swiping In Android App
Also nosotros wants to swipe bottom to grade off in addition to grade off to bottom vertically as shown inwards bellow Image.


This is our finish to arrive at from this post.

Create And Run Appium Android Test Script To Swipe
I accept prepared uncomplicated examination to perform swipe on SwipeListView Demo android app every bit shown bellow. Create novel degree file driverSwipe.java in addition to glue bellow given examination script code inwards it.

driverSwipe.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.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace degree driverSwipe {  AndroidDriver driver;  Dimension size;  @BeforeTest  populace 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", "com.fortysevendeg.android.swipelistview");   capabilities.setCapability("appActivity","com.fortysevendeg.android.swipelistview.sample.activities.SwipeListViewExampleActivity");   driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);   WebDriverWait await = novel WebDriverWait(driver, 300);   wait.until(ExpectedConditions.elementToBeClickable(By.className("android.widget.RelativeLayout")));  }   @Test  populace void swipingHorizontal() throws InterruptedException {   //Get the size of screen.   size = driver.manage().window().getSize();   System.out.println(size);      //Find swipe origin in addition to halt signal from screen's amongst in addition to height.   //Find startx signal which is at correct side of screen.   int startx = (int) (size.width * 0.70);   //Find endx signal which is at left side of screen.   int endx = (int) (size.width * 0.30);   //Find vertical signal where you lot wants to swipe. It is inwards middle of covert height.   int starty = size.height / 2;   System.out.println("startx = " + startx + " ,endx = " + endx + " , starty = " + starty);    //Swipe from Right to Left.   driver.swipe(startx, starty, endx, starty, 3000);   Thread.sleep(2000);    //Swipe from Left to Right.   driver.swipe(endx, starty, startx, starty, 3000);   Thread.sleep(2000);  }   @Test  populace void swipingVertical() throws InterruptedException {   //Get the size of screen.   size = driver.manage().window().getSize();   System.out.println(size);       //Find swipe origin in addition to halt signal from screen's amongst in addition to height.   //Find starty signal which is at bottom side of screen.   int starty = (int) (size.height * 0.80);   //Find endy signal which is at grade off side of screen.   int endy = (int) (size.height * 0.20);   //Find horizontal signal where you lot wants to swipe. It is inwards middle of covert width.   int startx = size.width / 2;   System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx);    //Swipe from Bottom to Top.   driver.swipe(startx, starty, startx, endy, 3000);   Thread.sleep(2000);   //Swipe from Top to Bottom.   driver.swipe(startx, endy, startx, starty, 3000);   Thread.sleep(2000);  }   @AfterTest  populace void End() {   driver.quit();  }  }

swipingHorizontal() Method Description
In higher upwards examination script, swipingHorizontal() method is responsible for horizontal swipe. Here,
  • driver.manage().window().getSize(); volition disclose your device's covert size(Width X Height).
  • startx Is located at 70% (From left) of your device's covert width.
  • endx Is located at 30%  (From left) of your device's covert width.
  • starty Is located at the vertical middle of the screen.
  • First driver.swipe method will swipe from correct side to left side every bit swipe origin point(startx) is located at right side of the covert in addition to halt point(endx) is locate at left side of the screen. Here 3000 Is fourth dimension inwards milliseconds to perform swipe operation. 
  • Second driver.swipe method will swipe from left side to correct side every bit swipe origin point(endx) is located at left side of the covert in addition to halt point(startx) is locate at correct side of the screen.
  • Vertical point starty will stay steady every bit nosotros are performing horizontal swipe.
swipingVertical() Method Description
swipingHorizontal() method is responsible for vertical swipe In higher upwards android automation script . Here,
  • starty Is located at 80% (From top) of your device's covert height.
  • endy Is located at 20%  (From top) of your device's screen height.
  • startx Is located at the horizontal middle of the screen.
  • First driver.swipe method volition swipe from bottom to grade off every bit swipe origin point(starty) is located at bottom side of the covert in addition to halt point(endy) is locate at grade off side of the screen. Here 3000 Is fourth dimension inwards milliseconds to perform swipe operation. 
  • Second driver.swipe method volition swipe from grade off side to bottom every bit swipe origin point(endy) is located at grade off side of the covert in addition to halt point(starty) is locate at bottom side of the screen.
  • Horizontal point startx will stay steady every bit nosotros are performing horizontal swipe.
I hope, Now you lot aware most how to run appium examination script In android mobile device. Start appium server in addition to run examination script inwards eclipse in addition to disclose swipe functioning inwards your android mobile screen.

This means you lot tin swipe horizontal or vertical inwards whatever android application.

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