Appium Gesture function: Swipe horizontal and vertical

Most of gestures behavior on mobile is scroll, swipe, so many test case on mobile should be focus on it. Appium have function/api to simulate this action as well.

Swipe vertical


public static void swipeVertical(double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {

Dimension size = driver.manage().window().getSize();

int anchor = (int) (size.width * anchorPercentage);

int startPoint = (int) (size.height * startPercentage);

int endPoint = (int) (size.height * finalPercentage);

new TouchAction(driver).press(anchor, startPoint).waitAction(duration).moveTo(anchor, endPoint).release().perform();

 

//In documentation they mention moveTo coordinates are relative to initial ones, but thats not happening. When it does we need to use the function below

//new TouchAction(driver).press(anchor, startPoint).waitAction(duration).moveTo(0,endPoint-startPoint).release().perform();

}

 

Swipe horizontal


public static void swipeHorizontal(double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {

Dimension size = driver.manage().window().getSize();

int anchor = (int) (size.height * anchorPercentage);

int startPoint = (int) (size.width * startPercentage);

int endPoint = (int) (size.width * finalPercentage);

new TouchAction(driver).press(startPoint, anchor).waitAction(duration).moveTo(endPoint, anchor).release().perform();

//In documentation they mention moveTo coordinates are relative to initial ones, but thats not happening. When it does we need to use the function below

//new TouchAction(driver).press(startPoint, anchor).waitAction(duration).moveTo(endPoint-startPoint,0).release().perform();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s