Screenshot testing Android Apps

This guide will walk you through every step of integrating Screenshotbot into your Android projects. We provide a Gradle plugin that offers a simple solution for capturing screenshots within your Android app development workflow.

Our Gradle plugin works with the following Screenshot testing libraries:

Screenshotbot is agnostic about how you generated your screenshots. As long as you can provide us a directory of screenshots during your Continuous Integration (CI) job, you can integrate with us. This means if you're not using one of the above libraries, or you use some custom internal library, you can still integrate with Screenshotbot.

Integrating with the Screenshotbot Gradle plugin

The Screenshotbot Gradle plugin automatically detects your screenshot testing library (Paparazzi, screenshot-tests-for-android, Shot) and configures itself accordingly. Here's how to integrate:

  1. Add the plugin:

      plugins {
        id 'io.screenshotbot.plugin' version '1.14'
      }
    Add this line to your root module's build.gradle // in sub-module file.
  2. Apply the plugin (in sub-modules)

      apply plugin: 'io.screenshotbot.plugin'
    Add this line to the build.gradle file of each sub-module containing screenshot tests. At this point you could test run your screenshot tests locally if you like.
  3. Run your screenshot tests on CI

    You must call the right task on CI depending on the screenshot testing library you're using. You might have to tweak the below targets based on the flavor of the build.
    • For Compose Preview Screenshot Tests:
        ./gradlew recordAndVerifyDebugScreenshotTest
    • For Papparazzi:
        ./gradlew recordAndVerifyPaparazziDebugScreenshotbotCI
    • For Roborazzi:
        ./gradlew recordRoborazziDebugScreenshotbotCI
    • For Shot:
        ./gradlew recordAndVerifyDebugAndroidScreenshotbotCI
    • For screenshot-tests-for-android:
        ./gradlew recordAndVerifyDebugAndroidScreenshotbotCI
    • For Dropshots:
        ./gradlew connectedDebugAndroidTestScreenshotbot -Precord=true
  4. Create an API key on Screenshotbot

    Once you set up your account, you can create an API Key from here. Copy the API key and secret to your CI framework (CircleCI/Jenkins/Bitrise etc.). Most CI frameworks will have a way of specifying environment variables or secrets. We need the following two environment variables:
      SCREENSHOTBOT_API_KEY=...
      SCREENSHOTBOT_API_SECRET=...

Add old screenshots to.gitignore

Screenshotbot does not require you to save any screenshots in your repository. (But it is safe if you do so.)

Your team members might still try to run the old Gradle tasks, which will generate screenshots. To avoid confusion, you might want to prevent them from commiting those screenshots into your repository. You can add those screenshots to .gitignore as follows:

  • For Compose Preview Screenshot Tests
      **/screenshotTest/reference
  • For Paparazzi:
      **/test/snapshots
  • For Roborazzi, you can ignore this step
  • For Shot
      **/screenshots/debug
  • For screenshot-tests-for-android:
      **/screenshots/API*/*.png
  • For Dropshots:
      **/androidTest/screenshots

Local Runs

You can also use the Gradle plugin to run screenshot tests locally (i.e. not on CI).

See this page to understand how record and verify works in this flow.

For each of the libraries, we generate a record and a verify task that can be run locally.

Example Repositories

Compose Previews screenshotbot/compose-preview-example
Paparazzi screenshotbot/paparazzi-example
Shot screenshotbot/shot-example
screenshot-tests-for-android screenshotbot/screenshot-tests-for-android-example

Next Steps

At this point, you will get email notifications each time your screenshots change.

To get notifications on your Pull Request, follow the integration steps corresponding to your You can then integration with your Code Review platform of you choice (for example, GitHub), to get build statuses.

Ready to get started?

Sign up or contact us.