Kelvin Low
Kelvin Low

Reputation: 400

Java Appium Test failed to run on AWS Device Farm

I have Appium script in Java language which recoreded by Appium Insecptor.

My script is going to do only 5 steps:

  1. Click username field

  2. Input username

  3. Click password field

  4. Inout password

  5. Click login button

I would like to run my script on AWS Device Farm.

I did follow the document of AWS Device Farm to modify my pom.xml file, packaged it by using Maven package mvn clean package -Dskiptests=true and finally uploaded the zip-with-dependencies.zip to AWS Device Farm.

But my test failed to run. Here are the screenshots of the result

Screenshot of my result 1 Screenshot of my result 2

I don't know where I did mistake to make AWS failed to run my script.

Here is what I recorded,

package com.hostname.myapp;

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

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;


public class AppiumTest {

    private static AppiumDriver<AndroidElement> wd;

    @BeforeClass
    public static void setUpClass() throws MalformedURLException {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("appium-version", "1.0");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "5.0.2");
        capabilities.setCapability("deviceName", "XXXXXXXXXXXX");
        capabilities.setCapability("app", "/Users/X/X.apk");
        capabilities.setCapability("appPackage", "com.hostname.myapp");
        wd = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
        wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    }

    @AfterClass
    public static void tearDownClass() {
        if (wd != null) {
            wd.quit();
        }
    }

    @Test
    public void test() throws IOException {
        wd.findElement(By.xpath("android.widget.EditText[1]")).click();
        wd.findElement(By.xpath("android.widget.EditText[1]")).sendKeys("username");
        wd.findElement(By.xpath("android.widget.EditText[2]")).click();
        wd.findElement(By.name("Android.widget.EditText[2]")).sendKeys("password");
        wd.findElement(By.xpath("android.widget.Button[1]")).click();
        wd.close();
    } 

Upvotes: 0

Views: 1250

Answers (1)

NikofTime
NikofTime

Reputation: 749

I work for the AWS Device Farm team.

Thank you for the detailed information. This helps.

Solution

  1. Desired Capabilities: Device farm ignores the desired capabilities that you have used. Since you upload the app separately in device farm and choose the device while scheduling a run the device type, name and other capabilities that you use in your code will not be honored and any code that depends on it most likely will not work. Creating an empty desired capability object and passing that to the AndroidDriver constructor would be the ideal way to approach this.

  2. Android Driver: The code that you used

    wd = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

    should be

    wd = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

  3. Video: We have video recording capability for both iOS and Android. When a test fails it helps immensely if there is a video of that run. You can check this under the "Files" tab. It could be the case that a pop appeared on the device or some other unexpected event while running the test. The video should give you more insight in this case.

I would suggest trying these 3 changes. Let me know if you are still unable to proceed.

Hope this helps.

Upvotes: 3

Related Questions