I am using AppiumDriver to install android application on Amazon device farm. And i have tested this in real device and it's working perfectly fine but when I am putting same code into Device Farm at that time it want work. It want open play store application and get below error.
Unable to create a new remote session. Original error: connect timed out Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'ip-172-31-13-65', ip: '172.31.13.65', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-139-generic', java.version: '1.8.0_151' Driver info: driver.version: AndroidDriver Tests failed
Please check below code for it.
@Before
public void setup() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.UDID, "FA8351A00767");
desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Google Pixel 2");
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9");
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
desiredCapabilities.setCapability(MobileCapabilityType.NO_RESET, true);
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), desiredCapabilities);
if (!isShopperAppAvailable()) {
desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.android.vending");
desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,
"com.google.android.finsky.activities.MainActivity");
} else {
desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "your application package");
desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,
"your app's launcher activity");
}
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), desiredCapabilities);
}
public boolean isShopperAppAvailable() {
boolean isShopperAppAvailable = false;
if (driver != null) {
isShopperAppAvailable = driver.isAppInstalled("your application package");
}
return isShopperAppAvailable;
}
@Test
public void testGooglePlayApp() throws InterruptedException {
if (!isShopperAppAvailable()) {
String appName = "Search your application";
driver.findElementById("com.android.vending:id/0_resource_name_obfuscated").click();
Thread.sleep(500);
driver.findElementByXPath(
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.view.ViewGroup/android.widget.LinearLayout/android.widget.EditText")
.sendKeys(appName);
Thread.sleep(500);
driver.findElement(By.xpath(
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.FrameLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.support.v7.widget.RecyclerView/android.widget.LinearLayout"))
.click();
Thread.sleep(500);
MobileElement installButton = (MobileElement) driver.findElementByXPath(
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.FrameLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.Button");
installButton.click();
Thread.sleep(10000);
} else {
System.out.println("open your app and do something");
}
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
The problem is that you need to install your Google account onto Device Farm devices before downloading apps from the app store. I have developed sample code for doing both of these things (installing your account and downloading apps) here: https://github.com/aristeia/GoogleAccountSignInScript . Please give this a try and let me know your thoughts.
Thanks, Jon
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.