To apply the testng.xml file to the Appium TestNG test package for AWS Device Farm, I need to add the testng.xml file to the root of the *-tests.jar file. How do I do that?

To demonstrate using the testng.xml file, you can use the Device Farm Appium tests project from the aws-samples GitHub page, create the testng.xml file, and then use Maven to package the tests. Then, using the Device Farm sample app for Android project from the aws-samples GitHub page, you can build a sample Android application to use on a test device.

Note: In Device Farm's standard environment only a subset of features are supported for the testng.xml file. If priority, the include tag, the exclude tag, complex grouping, or using parameters from the testng.xml file are required for the project, then use the custom environments.

1.    Download or clone the aws-device-farm-appium-tests-for-sample-app Java testing sample project, extract the project if necessary, and then change the active directory to that project.

cd aws-device-farm-appium-tests-for-sample-app/

2.    Create the /src/test/resources directory:

mkdir src/test/resources

The Super POM is configured to add all the files in the resources directory to the *- tests.jar file.

To view the Super POM of the project, run this command:

mvn help:effective-pom

Alternatively, you can implement the testResources tags in the pom.xml to explicitly reference another directory besides src/test/resources:


3.    Create the testng.xml file in the src/test/resources directory, and then add the AlertPageTest class to the file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="Default Suite">
    <test name="test">
            <class name="Tests.AlertPageTest"/> <!--Package.ClassName-->

4.    Modify the pom.xml to include the surefire plugin to reference the testng.xml file for local executions:

       <suiteXmlFiles> <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile></suiteXmlFiles>

This is optional if the project is going to be executed in just the Device Farm. However, it's a best practice to run tests locally before uploading them to Device Farm.

5.    Delete the contents of the target directory, and then package the tests using the clean and package Maven commands. The -DskipTests=true option specifies that the build shouldn't run the unit tests.

mvn clean package -DskipTests=true

The package command creates the file in the target directory with the *-tests.jar file.

6.    Use the xf command to extract the jar to verify that the testng.xml file is in the root:

jar xf nameOfTheProjectFromPom-1.0-SNAPSHOT-tests.jar

Alternatively, the unzip command can also extract the contents of the jar:

unzip nameOfTheProjectFromPom-1.0-SNAPSHOT-tests.jar -d sampletestsjarcontents

7.    Clone the sample android application aws-device-farm-sample-app-for-android from aws-samples on GitHub, and then use it for a test in Device Farm.

Clone this project, or download a zip version of it, and then change to the /aws-device-farm-sample-app-for-android directory:

git clone
cd aws-device-farm-sample-app-for-android/

8.    Add the ANDROID_HOME variable to your path if it isn't already there, and then build the project.

For Windows:

Set the ANDROID_HOME variable in your path environmental variables.

Build the project by running the gradle command with an assembleDebug parameter:

gradlew.bat assembleDebug

For macOS or Linux:

Add the following line to the /.bash_profile file:

export ANDROID_HOME=/Users/$(whoami)/Library/Android/sdk

Reload the profile using the source command:

source ~/.bash_profile

Build the project by executing the gradle command with a assembleDebug parameter:

./gradlew assembleDebug

This creates an app-debug.apk file in the ./app/build/outputs/apk directory that is used in the testing on Device Farm.

9.    Schedule a test in Device Farm, and then validate that it ran only the tests in the Class

All suites (Setup Suite, Tests.AlertPageTest, Teardown Suite) should show that they've succeeded.

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center.

Published: 2018-09-26