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

Working with Instrumentation for Android and AWS Device Farm

Device Farm provides support for Instrumentation (JUnit, Espresso, Robotium, or any Instrumentation-based tests) for Android.

Device Farm also provides a sample Android application along with links to working tests in three Android automation frameworks, including Instrumentation (Espresso). You can download the Device Farm sample app for Android on GitHub.

What Is Instrumentation?

Android instrumentation enables you to invoke callback methods in your test code. This allows you to run through the lifecycle of a component step by step, as if you were debugging the component. For more information, see Instrumentation in the Testing Fundamentals section of the Android Developer Tools documentation.

Upload Your Android Instrumentation 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 Instrumentation, and then choose Upload.

  8. Browse to and choose the .apk file that contains your tests.

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

Taking Screenshots in Android Instrumentation Tests

You can take screenshots as part of your Android Instrumentation tests.

To take screenshots, call one of the following methods:

  • For Robotium, call the takeScreenShot method (for example, solo.takeScreenShot();).

  • For Spoon, call the screenshot method, for example:

    Copy
    Spoon.screenshot(activity, "initial_state"); /* Normal test code... */ Spoon.screenshot(activity, "after_login");

During a test run, Device Farm automatically gets screenshots from the following locations on the devices, if they exist, and then adds them to the test reports:

  • /sdcard/robotium-screenshots

  • /sdcard/test-screenshots

  • /sdcard/Download/spoon-screenshots/test-class-name/test-method-name

  • /data/data/application-package-name/app_spoon-screenshots/test-class-name/test-method-name

Additional Considerations for Android Instrumentation Tests

System Animations

Per the Android documentation for Espresso testing, it is recommended that system animations are turned off when testing on real devices. Device Farm will automatically disable Window Animation Scale, Transition Animation Scale, and Animator Duration Scale settings when executing with the android.support.test.runner.AndroidJUnitRunner instrumentation test runner.

Test Recorders

Device Farm supports frameworks, such as Robotium, that have record-and-playback scripting tools.