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

Working with UI Automator for Android and AWS Device Farm

Device Farm provides support for UI Automator for Android.

Note

This framework is currently in preview and may not work with all scripts and apps.

What Is UI Automator?

The UI Automator testing framework provides a set of APIs to build user interface tests that perform interactions on user and system apps for Android. The UI Automator APIs allow you to perform operations such as opening the Settings menu or the app launcher in a test device. For more information, see UI Automator in the Testing Support Library section of the Android Developer Tools documentation.

Prepare Your Android UI Automator Tests

The Android UI Automator tests must be contained in a single JAR file before you upload them to Device Farm. The package name in this file must match the package name used by the related Android app. For example, if the Android app's package name is com.my.android.app.MyMobileApp, then the Android UI Automator tests must be in a package named com.my.android.app.

Upload Your Android UI Automator Tests

Use the Device Farm console to upload your tests:

  1. Sign in to the Device Farm console at https://console.aws.amazon.com/devicefarm.

  2. In the list of projects, choose the option next to the project where you want to upload your tests.

    Tip

    If the list of projects is not displayed, then on the secondary navigation bar, for Projects, choose the name of the project where you want to upload your tests.

    To create a new project, follow the instructions in Create a Project.

  3. If the Create a new run button is displayed, then choose it.

  4. On the Choose your application page, choose Upload.

  5. Browse to and choose your Android app file. The file must be an .apk file.

  6. Choose Next step.

  7. On the Configure a test page, choose uiautomator, and then choose Upload.

  8. Browse to and choose the JAR file that contains your tests. Make sure the Android tests are organized according to the instructions in Prepare Your Android UI Automator Tests.

  9. Choose Next step, and then complete the remaining on-screen instructions to select devices and start the run.

Taking Screenshots in Android UI Automator Tests

You can take screenshots as part of your Android UI Automator tests.

To take a screenshot, call the takeScreenshot method (for example, takeScreenshot("/sdcard/uiautomator-screenshots/home-screen-1234.png");).

Note

All screenshots must be stored in the /sdcard/uiautomator-screenshots directory. You must specify the full path (including the file name) of the screenshot to be stored.

The takeScreenshot method works for API Levels 17 and higher only. For API Level 16, UI Automator is supported, but screenshots are not supported.

Additional Considerations for Android UI Automator Tests

Device Farm re-signs Android UI Automator test packages, but it does not modify Android UI Automator tests.