Saturday, 7 October 2017

Swipe Right,Left,Up & Down using Appium

This is very useful tutorial for those who are learning appium as swiping and scrolling is commonly used for almost all mobile apps. So learning to automate it using Appium is going to help you in writing test code.Below is the code where I have written different functions for swiping from top to bottom, from bottom to top, from left to right, from right to left using Appium. We can all these methods in our test cases to perform required actions. plus I have created a video tutorial with detailed explanation.



/**
  /* Method to swipe screen from Bottom to Top (Vertical) Get the size of
  * screen. Find swipe start and end point from screen's width and height.
  * Find starty point which is at bottom side of screen. Find endy point
  * which is at top side of screen. Find horizontal point where you wants to
  * swipe. It is in middle of screen width.
  * Time duration should be in milliseconds
  */

 public void bottomTopswipe(int timeduration) {

  
  size = driver.manage().window().getSize();
  System.out.println(size);
  starty = (int) (size.height * 0.50);
  endy = (int) (size.height * 0.20);
  startx = size.width / 2;
  System.out.println("Start swipe operation");
  driver.swipe(startx, starty, startx, endy, timeduration);

 }

 /**
  * 
  * Method to swipe screen from Top to Bottom (Vertical) Get the size of
  * screen. Find swipe start and end point from screen's width and height.
  * Find starty point which is at bottom side of screen. Find endy point
  * which is at top side of screen. Find horizontal point where you wants to
  * swipe. It is in middle of screen width. 
         * Time duration should be in milliseconds
   */

 public void topBottomswipe(int timeduration) {

  
  size = driver.manage().window().getSize();
  System.out.println(size);
  starty = (int) (size.height * 0.50);
  endy = (int) (size.height * 0.20);
  startx = size.width / 2;
  System.out.println("Start swipe operation");
  driver.swipe(startx, endy, startx, starty, timeduration);

 }

 /**
  * 
  * Method to swipe screen from right to left (Horizontal) duration should be
  * in milliseconds Get the size of screen. Find swipe start and end point
  * from screen's width and height. Find startx point which is at right side
  * of screen. Find endx point which is at left side of screen. Find vertical
  * point where you wants to swipe. It is in middle of screen height. 
         * Time duration should be in milliseconds
   */

 public void rightLeftSwipe(int timeduration) {

  size = driver.manage().window().getSize();
  System.out.println(size);
  startx = (int) (size.width * 0.70);
  endx = (int) (size.width * 0.30);
  starty = size.height / 2;
  System.out.println("Start swipe operation");
  driver.swipe(startx, starty, endx, starty, timeduration);

 }

 /**
  * 
  * Method to swipe screen from left to right (Horizontal) duration should be
  * in milliseconds Get the size of screen. Find swipe start and end point
  * from screen's width and height. Find startx point which is at right side
  * of screen. Find endx point which is at left side of screen. Find vertical
  * point where you wants to swipe. It is in middle of screen height. 
         * Time duration should be in milliseconds
      */

 public void leftRightSwipe(int timeduration) {
  // duration should be in milliseconds
  size = driver.manage().window().getSize();
  System.out.println(size);
  startx = (int) (size.width * 0.70);
  endx = (int) (size.width * 0.30);
  starty = size.height / 2;
  System.out.println("Start swipe operation");
  driver.swipe(endx, starty, startx, starty, timeduration);

 }

2 comments:


  1. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...
    Texting API
    SMS API
    SMS Marketing

    ReplyDelete