package Day4;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
public class drag_drop {
public AndroidDriver driver;
public Process process;
//Starting the server
public void Start_Server() throws IOException, InterruptedException
{
String Start_server="D:\\Appium\\node.exe D:\\Appium\\node_modules\\appium\\bin\\appium.js";
process = Runtime.getRuntime().exec(Start_server);
if(process!=null)
{
System.out.println("Appium server is Running");
}
else
{
System.out.println("Not started the Server");
}
Thread.sleep(12000);
}
//Initialize app
public void InitializeApp() throws MalformedURLException, InterruptedException
{
DesiredCapabilities capabilities= new DesiredCapabilities();
//device details
capabilities.setCapability("deviceName", "xxxx");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "6.0");
//app details
capabilities.setCapability("appPackage", "com.mobeta.android.demodslv");
capabilities.setCapability("appActivity", "com.mobeta.android.demodslv.Launcher");
//Appium Server details
driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(4000);
}
//perform dragdrop
public void perform_dragdrop() throws InterruptedException
{
driver.findElementByXPath("//*[@class='android.widget.TextView'][@text='CursorAdapter']").click();
Thread.sleep(2000);
List<WebElement> ele_draghdl = driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle");
System.out.println(ele_draghdl.size());
TouchAction action= new TouchAction(driver);
action.longPress(ele_draghdl.get(0)).moveTo(ele_draghdl.get(5)).release().perform();
Thread.sleep(8000);
}
public void Stop_Server() throws InterruptedException
{
if(process!=null)
{
process.destroy();
Thread.sleep(8000);
System.out.println("Stopped the Appium Server");
}
}
}
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
public class drag_drop {
public AndroidDriver driver;
public Process process;
//Starting the server
public void Start_Server() throws IOException, InterruptedException
{
String Start_server="D:\\Appium\\node.exe D:\\Appium\\node_modules\\appium\\bin\\appium.js";
process = Runtime.getRuntime().exec(Start_server);
if(process!=null)
{
System.out.println("Appium server is Running");
}
else
{
System.out.println("Not started the Server");
}
Thread.sleep(12000);
}
//Initialize app
public void InitializeApp() throws MalformedURLException, InterruptedException
{
DesiredCapabilities capabilities= new DesiredCapabilities();
//device details
capabilities.setCapability("deviceName", "xxxx");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "6.0");
//app details
capabilities.setCapability("appPackage", "com.mobeta.android.demodslv");
capabilities.setCapability("appActivity", "com.mobeta.android.demodslv.Launcher");
//Appium Server details
driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(4000);
}
//perform dragdrop
public void perform_dragdrop() throws InterruptedException
{
driver.findElementByXPath("//*[@class='android.widget.TextView'][@text='CursorAdapter']").click();
Thread.sleep(2000);
List<WebElement> ele_draghdl = driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle");
System.out.println(ele_draghdl.size());
TouchAction action= new TouchAction(driver);
action.longPress(ele_draghdl.get(0)).moveTo(ele_draghdl.get(5)).release().perform();
Thread.sleep(8000);
}
public void Stop_Server() throws InterruptedException
{
if(process!=null)
{
process.destroy();
Thread.sleep(8000);
System.out.println("Stopped the Appium Server");
}
}
}