AWS Device Farm
Developer Guide (API Version 2015-06-23)

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Working with Appium Java TestNG for Android and AWS Device Farm

This section describes how to configure, package, and upload your Appium Java TestNG tests for Android to Device Farm. Appium is an open source tool for automating native and mobile web applications. For more information, see Introduction to Appium on the Appium website.

For a sample app and links to working tests, see Device Farm Sample App for Android on GitHub.

You can also use behavior-driven development tools such as Cucumber with your Appium Java tests. For a sample test, see Appium Java TestNG and Cucumber Tests for the Device Farm Android Sample App on GitHub.

Version Information

  • Currently, Device Farm supports Java 8 for running Appium Java tests.

  • Device Farm supports all Appium server versions 1.6.5 and above. You can choose any Appium version by using the avm command. For example, to use Appium server version 1.9.1, add these commands to your test spec YAML file:

    phases: install: commands: # To install a newer version of Appium such as version 1.9.1: - export APPIUM_VERSION=1.9.1 - avm $APPIUM_VERSION - ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js

    To use all the features of the framework, like annotations, choose a custom test environment, and use the AWS CLI or the Device Farm console to upload a custom test spec.

    For more information, see Uploading a Custom Test Spec Using the AWS CLI and Create a Test Run in AWS Device Farm.

Step 1: Configure Your Appium Test Package

Use the following instructions to configure your test package. The Appium Java TestNG tests for your Android application must be contained in a .zip file.

Update Your Maven Settings

  1. Modify pom.xml to set packaging to a JAR file:

    <groupId>com.acme</groupId> <artifactId>acme-android-appium</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging>
  2. Modify pom.xml to use maven-jar-plugin to build your tests into a JAR file.

    The following plugin builds your test source code (anything in the src/test directory) into a JAR file:

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <executions> <execution> <goals> <goal>test-jar</goal> </goals> </execution> </executions> </plugin>
  3. Modify pom.xml to use maven-dependency-plugin to build dependencies as JAR files.

    The following plugin copies your dependencies into the dependency-jars directory:

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${}/dependency-jars/</outputDirectory> </configuration> </execution> </executions> </plugin>

Step 2: Configure Your Tests to Run with Cucumber (Optional)

  • If you use Cucumber with your Appium Java TestNG for Android tests, use this step to configure Maven with your Cucumber settings. Otherwise, skip to the next step.


    You must run your tests in a custom test environment to use Cucumber with your Appium tests.

    1. Modify pom.xml to add cucumber-java as a dependency.

      <!-- --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>4.0.0</version> </dependency>
    2. Modify pom.xml to add cucumber-testng as a dependency.

      <!-- --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>4.0.0</version> </dependency>

Step 3: Create a Zipped Test Package File

  1. Save the following XML assembly to src/main/assembly/zip.xml.

    The following XML is an assembly definition that, when configured, instructs Maven to build a .zip file that contains everything in the root of your build output directory and the dependency-jars directory:

    <assembly xmlns="" xmlns:xsi="" xsi:schemaLocation=""> <id>zip</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${}</directory> <outputDirectory>./</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> <fileSet> <directory>${}</directory> <outputDirectory>./</outputDirectory> <includes> <include>/dependency-jars/</include> </includes> </fileSet> </fileSets> </assembly>
  2. Modify pom.xml to use maven-assembly-plugin to package tests and all dependencies into a single .zip file.

    The following plugin uses the preceding assembly to create a .zip file named zip-with-dependencies in the build output directory every time mvn package is run:

    <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.5.4</version> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <finalName>zip-with-dependencies</finalName> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assembly/zip.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin>
  3. Build, package, and verify. For example:

    $ mvn clean package -DskipTests=true $ tree target . |— acme-android-appium-1.0-SNAPSHOT.jar (this is the JAR containing everything built from the ./src/main directory) |— acme-android-appium-1.0-SNAPSHOT-tests.jar (this is the JAR containing everything built from the ./src/test directory) |— (this .zip file contains all of the items) `— dependency-jars (this is the directory that contains all of your dependencies, built as JAR files) |— |— com.another-dependency.thing-1.0.jar |— joda-time-2.7.jar |— log4j-1.2.14.jar |— (and so on...)
  4. Use the Device Farm console to upload the test package.


If you receive an error that says annotation is not supported in 1.3, add the following to pom.xml:

<plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin>

Step 4: Upload Your Test Package to Device Farm

You can use the Device Farm console to upload your Appium Java TestNG for Android tests.

  1. Sign in to the Device Farm console at

  2. If you see the AWS Device Farm console home page, enter a name for your project, and then choose Create project. Refresh the page to see your new project.

  3. If you already have a project, you can upload your tests to it.

  4. Open your project, and then choose Create a new run.

  5. On the Choose your application page, choose Android native application ( 
        Android icon.
    ), and then choose Upload.

        Choose an application in the Device Farm console.
  6. Browse to and choose your Android app file. The file must be an .apk file.

  7. Choose Next step.

  8. On the Configure a test page, choose Appium Java TestNG, and then choose Upload.

  9. Browse to and choose the .zip file that contains your tests. The .zip file must follow the format described in Step 1: Configure Your Appium Test Package.

  10. Choose the Appium version you are using.

  11. Choose Next step, and then follow the instructions to select devices and start the run. For more information, see Create a Test Run in AWS Device Farm.


Device Farm does not modify Android Appium Java TestNG tests.

Step 5: Take Screenshots of Your Android Appium Java TestNG Tests (Optional)

You can take screenshots as part of your tests.

When Device Farm runs your Appium Java TestNG test, the service sets the following system properties that describe the configuration of the Appium server with which you're communicating:

  • appium.screenshots.dir: Path where the screenshots are saved.

  • appium.server.address: Host address of the Appium server.

  • appium.server.port: Port on which the Appium server is listening.

Device Farm sets the SCREENSHOT_PATH property to a fully qualified path on the local file system where Device Farm expects Appium screenshots to be saved. The test-specific directory where the screenshots are stored is defined at runtime. The screenshots are pulled into your Device Farm reports automatically. To view the screenshots, in the Device Farm console, choose the Screenshots section.

The following example shows how to use and consume the appium.screenshots.dir property to capture an Appium screenshot that is pulled into your Device Farm report.

public boolean takeScreenshot(final String name) { String screenshotDirectory = System.getProperty("appium.screenshots.dir", System.getProperty("", "")); File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); return screenshot.renameTo(new File(screenshotDirectory, String.format("%s.png", name))); }