Run CMD
cd C:\Users\NEERAJ\Desktop\adt-bundle-windows-x86_64-20140321
java -jar selenium-server-standalone-2.42.1.jar -role hub
You Need to write Json File for 1st Device
{
"capabilities":
[
{
"browserName": "chrome",
"version": "5.0.2",
"maxInstances": 2,
"platform": "ANDROID",
"deviceName": "TA93305G0L"
}
],
"configuration":
{
"nodeTimeout":120,
"port":4725,
"hubPort":4444,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://127.0.0.1:4725/wd/hub", //mention same port in url as mentioned above
"hub": "127.0.0.1:4444/grid/register",
"hubHost":"127.0.0.1",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":2000,
"timeout":30000,
"maxSession":2
}
}
In another window run below command
C:\Program Files (x86)>node.exe Appium\node_modules\appium\bin\appium.js --address 127.0.0.1 --port 4725 -bp 2252 --udid TA93305G0L --nodeconfig C:\Users\NEERAJ\Desktop\node.json --session-override
Note in above file you need to write port and in the url also you need to mention same port
Similarly create another Node File for 2nd Device
{
"capabilities":
[
{
"browserName": "chrome",
"version": "5.0.2",
"maxInstances": 2,
"platform": "ANDROID",
"deviceName": "ZY2227L635" //take from adb devices
}
],
"configuration":
{
"nodeTimeout":120,
"port":4726,
"hubPort":4444,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://127.0.0.1:4726/wd/hub",
"hub": "127.0.0.1:4444/grid/register",
"hubHost":"127.0.0.1",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":2000,
"timeout":30000,
"maxSession":2
}
}
Run the following command in the console
C:\Program Files (x86)>node.exe Appium\node_modules\appium\bin\appium.js --address 127.0.0.1 --port 4726 -bp 2254 --udid ZY2227L635 --nodeconfig C:\Users\NEERAJ\Desktop\node1.json --session-override
TestNG.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- Specify the test suite name -->
<suite name="CS_Regression" annotations="JDK" parallel="tests" thread-count="2">
<test name="Device_MotoXplay">
<parameter name = "Device_ID" value="ZY2227L635" />
<classes>
<class name="com.neeraj.project.TestProject" />
<methods>
<include name= "TestProject"/>
</methods>
</classes>
</test>
<test name="Device_MotoG">
<parameter name = "Device_ID" value="TA93305G0L" />
<classes>
<class name="com.neeraj.project.TestProject" />
<methods>
<include name="TestProject"/>
</methods>
</classes>
</test>
</suite>
Following program
package com.neeraj.project.TestProject;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
import io.appium.java_client.remote.MobileCapabilityType;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestProject{
AndroidDriver driver;
DesiredCapabilities cap = new DesiredCapabilities();
String URL;
@Parameters("Device_ID")
@BeforeTest
public void setupcap(String Device_ID) throws MalformedURLException
{
if(Device_ID.equalsIgnoreCase("ZY2227L635")) // Moto X Play
{
setupcapabilities(Device_ID);
System.out.println("Moto X Play");
driver = new AndroidDriver(new URL("http://127.0.0.1:4726/wd/hub"), cap);
}
if(Device_ID.equalsIgnoreCase("TA93305G0L")) // Moto G
{
setupcapabilities(Device_ID);
System.out.println("Moto G");
driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"), cap);
}
}
public void setupcapabilities(String device)
{
File appDir = new File("C://Users//NEERAJ//workspace//project");
File app = new File(appDir, "com.test_4.5.5.apk");
cap.setCapability("deviceName", device);
cap.setCapability("automationName", "Appium");
cap.setCapability("platformName", "ANDROID");
cap.setCapability("app-package", "com.test");
cap.setCapability("app-activity", "com.test.activities.ActivityMain");
cap.setCapability("udid", device);
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
}
@Test
public void testApp(String Device_ID) throws InterruptedException, IOException{
if(Device_ID.equals("ZY2227L635")){
System.out.println("App launched on Moto X Play");
}
else if (Device_ID.equals("TA93305G0L")) {
System.out.println("App launched on Moto G");
}
Thread.sleep(15000);
driver.findElement(By.id("button_login_real")).click();
Thread.sleep(20000);
WebElement ele1 = driver.findElementById("rec_card_image");
WebElement ele2 = driver.findElementById("revised_pass");
//Perform drag and drop operation using TouchAction class. //Created object of TouchAction class.
TouchAction action = new TouchAction(driver);
System.out.println("It Is dragging element.");
action.longPress(ele1).moveTo(ele2).release().perform();
System.out.println("Element has been droped at destination successfully.");
}
@Test
public void testJabong1() throws InterruptedException, IOException{
System.out.println("App launched1");
Thread.sleep(15000);
driver.findElement(By.id("button_login_real")).click();
Thread.sleep(20000);
WebElement ele1 = driver.findElementById("rec_card_image");
WebElement ele2 = driver.findElementById("revised_pass");
//Perform drag and drop operation using TouchAction class. //Created object of TouchAction class.
TouchAction action = new TouchAction(driver);
System.out.println("It Is dragging element.");
action.longPress(ele1).moveTo(ele2).release().perform();
System.out.println("Element has been droped at destination successfully.");
}
@Test
public void testJabong2() throws InterruptedException, IOException{
System.out.println("App launched2");
Thread.sleep(15000);
driver.findElement(By.id("button_login_real")).click();
Thread.sleep(20000);
WebElement ele1 = driver.findElementById("rec_card_image");
WebElement ele2 = driver.findElementById("revised_pass");
//Perform drag and drop operation using TouchAction class. //Created object of TouchAction class.
TouchAction action = new TouchAction(driver);
System.out.println("It Is dragging element.");
action.longPress(ele1).moveTo(ele2).release().perform();
System.out.println("Element has been droped at destination successfully.");
}
}
No comments:
Post a Comment