Promotion

Screenshot Tests for Android

screenshot-tests-for-android is a library that can generate fast deterministic screenshots while running instrumentation tests on Android.

We mimic Android's measure(), layout() and draw() to generate screenshots on the test thread. By not having to do the rendering on a separate thread we have control over animations and handler callbacks which makes the screenshots extremely deterministic and reliable for catching regressions in continuous integration.

We also provide utilities for using screenshot tests during the development process. With these scripts you can iterate on a view or layout and quickly see how the view renders in a real Android environment, without having to build the whole app. You can also render the view in multiple configurations at one go.

In addition you'll find python code inside plugin/src/py. This code is packaged into the gradle plugin.

We have tests for the python code and the core library. Run these commands to run all the tests:

$ gradle :plugin:pyTests
$ gradle :core:connectedAndroidTest

Both need a running emulator.

Python tests rely on the mock and Pillow libraries. Both can be installed via pip install mock and pip install Pillow.

You can install all the artifacts to your local maven repository using

$ gradle installAll

Running With a Remote Service

For usage with a remote testing service (e.g. Google Cloud Test Lab) where ADB is not available directly the plugin supports a "disconnected" workflow. Collect all screenshots into a single directory and run the plugin using the following options

Example

The location of the screenshot artifacts can be configured in the project's build.gradle:

screenshots {
// Points to the directory containing all the files pulled from a device
referenceDir = path/to/screenshots
}