buttons

[appium-device-farm-15] — Step-by-Step Guide to Connect a ‘Real Device’ with “Appium Device Farm”

 

[appium-device-farm-15] — Step-by-Step Guide to Connect a ‘Real Device’ with “Appium Device Farm”

Get a step-by-step walkthrough in the video below!

Following Steps will be covered in the Article:
— — — — — — — — — — — — — — — — — — — — -

To connect Real Device(Physical Device):
— — — — — — — — — — — — — — — — — — — — —

Step-1: Connect the Real Device with vysor(optional Step).

Press enter or click to view image in full size

Step-2: Will Go through the required setting in Developer Options.

Step-3: Mirror the Real Device with Android Studio

Press enter or click to view image in full size

Launch Appium Server:
— — — — — — — — — — — — -

Step-4: Launch Appium Server with Device-Farm

Press enter or click to view image in full size

Step-5: Try to connect the Real Device.

Press enter or click to view image in full size

Step-6: check the error messages(if any)

Press enter or click to view image in full size

Steps to Resolve issue: (Very Important)
— — — — — — — — — — — — — — — — — — — —

Step-7: Install device-farm.apk

Press enter or click to view image in full size

Step-8: Install stream.apk

Press enter or click to view image in full size

Step-9: Try to reconnect with Real Device

Press enter or click to view image in full size

Step-10: Execute Our First Script on the Real Device:

package com.appiumguide.devicefarm;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebElement;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.net.*;
import java.time.Duration;

/**
* Script Details - "appium-device-farm”- Step-by-Step Guide to Connect a ‘Real Device’ with “Appium Device Farm”
*
* appium-java-client version: 9.5.0
*
* @author 'Ramesh Kodumuru' for AppiumGuide [appiumguide@gmail.com]
*/


public class devicefarm_FirstScriptOnRealDeviceDemo {

private AndroidDriver driver;

WebElement dragelement,dropelement;

@BeforeClass
public void setup() throws MalformedURLException {
UiAutomator2Options cap=new UiAutomator2Options();
cap.setPlatformName("android");
cap.setAutomationName("uiautomator2");
cap.setUdid("E6S8MJPFYHEUZDU8"); //UDID of Real Device


driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}

@Test
public void test1() throws InterruptedException {

driver.activateApp("com.wdiodemoapp");

Thread.sleep(5000);

driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"Drag\")")).click();



dragelement=driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.widget.ImageView\").instance(4)"));

dropelement=driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.view.ViewGroup\").instance(10)"));

int eX=(int)(dropelement.getRect().getX());
int eY=(int)(dropelement.getRect().getY());

//Perform Drag gesture based on element id, endX & endY co-ordinates
System.out.println("Perform Drag gesture based on element id, endX & endY co-ordinates");
((JavascriptExecutor) driver).executeScript("mobile: dragGesture",ImmutableMap.of("elementId",((RemoteWebElement) dragelement).getId(),
"endX",eX,
"endY",eY));

Thread.sleep(3000);
dragelement=driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.widget.ImageView\").instance(7)"));

int sX=(int)(dragelement.getRect().getX());
int sY=(int)(dragelement.getRect().getY());

dropelement=driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.view.ViewGroup\").instance(8)"));

int eX1=(int)(dropelement.getRect().getX());
int eY1=(int)(dropelement.getRect().getY());

//Perform Drag gesture based on element id, startX,startY,endX & endY co-ordinates
System.out.println("Perform Drag gesture based on element id, startX,startY,endX & endY co-ordinates");

((JavascriptExecutor) driver).executeScript("mobile: dragGesture",ImmutableMap.of(
"startX",sX,
"startY",sY,
"endX",eX1,
"endY",eY1));

Thread.sleep(3000);

////Perform Drag gesture based on element id,endX,endY co-ordinates and Speed

dragelement=driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.widget.ImageView\").instance(1)"));

dropelement=driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.view.ViewGroup\").instance(10)"));

int eX2=(int)(dropelement.getRect().getX());
int eY2=(int)(dropelement.getRect().getY());

int speedvalue=(int)(100*2.625);
System.out.println("Perform Drag gesture based on element id,endX,endY co-ordinates and Speed");

((JavascriptExecutor) driver).executeScript("mobile: dragGesture",ImmutableMap.of("elementId",((RemoteWebElement) dragelement).getId(),
"endX",eX2,
"endY",eY2,
"speed",speedvalue));

Thread.sleep(3000);

}

@AfterClass
public void teardown() {

if(driver!=null) {
driver.quit();
System.out.println("Test Execution Completed");

}

}

}

Observe that user able to connect Real Device with Device-Farm

Press enter or click to view image in full size

No comments:

Post a Comment