Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform swipe using appium in Java for android native app

I need to swipe my app(Both from left to right and right to left), wherelse I am using Java in appium for android native app automation.

I have tries this link, Swipe method not working in android automation testing

But i can't, is any other link please share or anyone help me out.

like image 209
user3540555 Avatar asked Apr 28 '14 11:04

user3540555


2 Answers

Here is how we do it-

Swipe left-

appiumDriver.context("NATIVE_APP"); 
Dimension size = appiumDriver.manage().window().getSize(); 
int startx = (int) (size.width * 0.8); 
int endx = (int) (size.width * 0.20); 
int starty = size.height / 2; 
appiumDriver.swipe(startx, starty, endx, starty, 1000);

Swipe right-

appiumDriver.context("NATIVE_APP"); 
Dimension size = appiumDriver.manage().window().getSize(); 
int endx = (int) (size.width * 0.8); 
int startx = (int) (size.width * 0.20); 
int starty = size.height / 2; 
appiumDriver.swipe(startx, starty, endx, starty, 1000);

Here appiumDriver is an instance of io.appium.java_client.AppiumDriver

like image 151
ABDUL SATHAR BEIGH Avatar answered Oct 12 '22 23:10

ABDUL SATHAR BEIGH


swipe() method is deprecated.

so we can use below methods.

Swipe left will be perform as:

new TouchAction(driver).longPress(250, 1200).moveTo(900, 1200).release().perform();

Swipe right will be perform as:

new TouchAction(driver).longPress(1000, 450).moveTo(500, 450).release().perform();

Here, driver is your driver like AndroidDriver, RemoteWebDriver, AppiumDriver.

And 250, 1200 and other is Your app view Co-ordinate that you can see in the UIAutomaterView batch file located under the android-sdk platform-tools.

like image 23
Pinak Gauswami Avatar answered Oct 12 '22 23:10

Pinak Gauswami