Tuesday, 19 January 2016

Java Appium - Performing Drag and Drop

Download 'Drag and Drop' demo app from play store.
 



Click 'INSTALL' button.


Click 'ACCEPT' button.




Launch 'ApkInfo' app to identify 'appPackage' and  'appActivity' of  'Drag-Sort Demos' app.

To know more about 'Apk Info' app watch the below video
http://automation-home.blogspot.com/2015/05/appium-java-executing-appium-webdriver-script.html

 
  
If you are new to Appium watch the video demo's present at
 

Sample Program:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

public class DragAndDropTest {
    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        AppiumDriver driver;

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "392c8ab5");
        capabilities.setCapability("platformVersion", "4.4.4");
      
//below statement is commented.
//I have already installed 'Drag-Sort Demos' app in my android device,
//so iam not installing the 'Drag-Sort Demos' app through appium for performing automation        //capabilities.setCapability("app",System.getProperty("user.dir")+"<<PATH of APK file>>");
      
        capabilities.setCapability("appPackage", "com.mobeta.android.demodslv");
        capabilities.setCapability("appActivity", ".Launcher");

        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                capabilities);
         driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
      

        driver.findElementByName("Basic usage playground").click();
      
        List<WebElement> elements = driver.findElements(By.id("com.mobeta.android.demodslv:id/drag_handle"));
        WebElement srcPos = elements.get(4);
        WebElement dstPos = elements.get(0);

        TouchAction ta = new TouchAction(driver);
        ta.longPress(srcPos).moveTo(dstPos).release();
        ta.perform();
      
            Thread.sleep(4000);
        driver.quit();
    }
}

No comments:

Post a Comment