Download Appium Tutorial - Perform Drag And Drop In Android App - Software Testing Tutorials graphic type that can be scaled to use with the Silhouette Cameo or Cricut. An SVG's size can be increased or decreased without a loss of quality. All of our downloads include an image, Silhouette file, and SVG file. It should be everything you need for your next project. Our SVG files can be used on adhesive vinyl, heat transfer and t-shirt vinyl, or any other cutting surface
- Right click on project(MavenProject1 for me) folder -> New -> Folder.
- Give folder name = Apps and click on Finish button. It will add Apps folder under project folder.
- Copy-paste downloaded Drag-Sort Demos apk file inside it as shown in bellow image.
- Install Drag Sort Demos app in android mobile device automatically.
- Then It will launch Drag Sort Demos app in your android mobile device.
- It will tap on "Basic usage playground" text.
- Then It will locate and drag 3rd element and drop it to 6th position as shown in bellow images.
- Android mobile device should be connected with PC with USB debugging mode enabled. View THIS POST.
- Drag-Sort Demos app should be there in Apps folder as described above.
- There should be enough free space in your mobile device to install Drag-Sort Demos app.
- appium node server should be launched and running mode. View THIS POST.
- TestNG should be installed in eclipse. View THIS POST.
Note : Please replace deviceName and platformVersion as per you actual in bellow given test.
DragAndDropAction.java
package Android;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class DragAndDropAction {
//Object reference of AndroidDriver.
AndroidDriver driver;
@BeforeTest
public void setUp() throws MalformedURLException {
//Set Drag-Sort Demos app folder path. This statement will refer project's folder path.
File classpathRoot = new File(System.getProperty("user.dir"));
//Set folder name "Apps" where .apk file is stored.
File appDir = new File(classpathRoot, "/Apps");
//Set Drag-Sort Demos .apk file name.
File app = new File(appDir, "com.mobeta.android.demodslv-0.5.0-3_APKdot.com.apk");
// Created object of DesiredCapabilities class.
DesiredCapabilities capabilities = new DesiredCapabilities();
// Set android deviceName desired capability. Set your device name.
capabilities.setCapability("deviceName", "ZX1B32FFXF");
// Set BROWSER_NAME desired capability. It's Android in our case here.
capabilities.setCapability("browserName", "Android");
// Set android VERSION desired capability. Set your mobile device's OS version.
capabilities.setCapability("platformVersion", "4.4.2");
// Set android platformName desired capability. It's Android in our case here.
capabilities.setCapability("platformName", "Android");
//Set .apk file's path capabilities.
capabilities.setCapability("app", app.getAbsolutePath());
// Set app Package desired capability of Drag-Sort Demos app.
capabilities.setCapability("appPackage", "com.mobeta.android.demodslv");
// Set app Activity desired capability of Drag-Sort Demos app.
capabilities.setCapability("appActivity", "com.mobeta.android.demodslv.Launcher");
// Created object of AndroidDriver and set capabilities.
// Set appium server address and port number in URL string.
// It will launch Drag-Sort Demos app in emulator.
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
@Test
public void dragDrop() {
//Tap on Basic usage Playground.
driver.findElementByName("Basic usage playground").click();
//Locate 3rd element(Chick Corea) from list to drag.
WebElement ele1 = (WebElement) driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(2);
//Locate 6th element to drop dragged element.
WebElement ele2 = (WebElement) driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(5);
//Perform drag and drop operation using TouchAction class.
//Created object of TouchAction class.
TouchAction action = new TouchAction((MobileDriver) driver);
System.out.println("It Is dragging element.");
//It will hold tap on 3rd element and move to 6th position and then release tap.
action.longPress(ele1).moveTo(ele2).release().perform();
System.out.println("Element has been droped at destination successfully.");
}
@AfterTest
public void End() {
// Quit
driver.quit();
}
}
- 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.
- It will launch Drag-Sort Demos app.
- Tap on "Basic usage playground" text and
- Perform draga and drop operation as shown in above Images.
Download Appium Tutorial - Perform Drag And Drop In Android App - Software Testing Tutorials All SVG file downloads also come bundled with DXF, PNG, and EPS file formats. All designs come with a small business commercial license. These SVG cut files are great for use with Silhouette Cameo or Cricut and other Machine Tools.