Road to scroll mobile application using Appium

Some time we need to scroll (swap ) screen to scroll application, it can be left, right up and down. You can use following function to achieve this.


public void scrollFormCenter(String direction) {

                         Dimension size = driver.manage().window().getSize();
                         switch (direction) {

                         case "up":
                                             int x = size.width / 2;
                                             int endy = (int) (size.height * 0.75);
                                             int starty = (int) (size.height * 0.20);
                                             driver.swipe(x, starty, x, endy, 1000);
                                             break;

                         case "down":
                                             x = size.width / 2;
                                             starty = (int) (size.height * 0.75);
                                             endy = (int) (size.height * 0.20);
                                             driver.swipe(x, starty, x, endy, 1000);
                                             break;

                         case "left":
                                             int y = (int) size.height / 2;
                                             int startx= (int) (size.width * 0.15);
                                             int endx  = (int) (size.width * 0.75);
                                             driver.swipe(startx, y, endx, y, 1000);
                                             break;

                         case "right":
                                             y = (int) size.height / 2;
                                             endx = (int) (size.width * 0.15);
                                             startx = (int) (size.width * 0.85);
                                             driver.swipe(startx, y, endx, y, 1000);
                                             break;
                         }
    }


Call this function in your code like below:


scrollFormCenter(down)               //for scrolling down
scrollFormCenter(left)                    //for scrolling down
scrollFormCenter(right)                  //for scrolling down
scrollFormCenter(up)                      //for scrolling down



2 comments:

  1. Thank you for benefiting from time to focus on this kind of, I feel firmly about it.



    android development

    ReplyDelete
  2. in this case swipe is not defined ,it showing like The method swipe(int, int, int, int, int) is undefined for the type AndroidDriver.

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution