Pages

Appium Tutorial - Perform Drag And Drop In Android App

Drag And Drop Is one of the common action of any android app. You will see many android mobile apps where you can drag and drop element from one place to other place. If you are automating android mobile app where you have to perform drag and drop then you need to use TouchAction class. TouchAction class provides us facility to automate mobile gestures of android app using appium. Let's take very simple example to perform drag and drop operation on android application using appium.

PREREQUISITES : Previous 18 steps (Listed In PART 1 and PART 2) of appium tutorials should be completed.

Download Drag-Sort Demos app

We will use Drag-Sort Demos app to perform drag and drop operation in android device. You can download it from Google Play Store or THIS PAGE.

Comments are already there with each sentence of test script. Let me describe you few Important class and methods which are used in above test script.

TouchAction : This is class of Webdriver 3 which provide different methods(longPress, moveTo, perform, press, tap, etc..) to automate mobile gestures like drag and drop, swipe etc. It will help us to generate action chain of different actions.

longPress : longPress is method to hold tap for long time on given element.

moveTo : moveTo is method to move action.

release : release is used to release from longPress tap action.

perform : perform will execute full action chain of drag and drop.

Also If you notice in above test script, We have used AndroidDriver at place of RemoteWebDriver as we are automating android app. And also used findElementByName("") and findElementsById("") methods at place of findElement(By.Name("")) and findElements(By.Id("")) methods.

Run above test using testng and observe Drag And Drop in your mobile device.

It will launch Drag-Sort Demos app.

Tap on "Basic usage playground" text and

Perform draga and drop operation as shown in above Images.

This way we can automate mobile gestures in appium android automation test. Same thing you can do with any app.

They are just warnings, sometime script works luckily even some warnings. here we are blessed.such warnings make me anxious, but I can do nothing.I think you have already known it. I happen to go back here. cheerMak

I guess you have to scroll down and then click on 9th element else it will give you exception. Selenium will count only visible elements in the screen, since 9th element is not visible, it will give exception.