Setting up Android Screenshots for CircleCI + Firebase

Your CircleCI job will call into Screenshotbot at the end of a test run. In order to make this call you first need to configure your API Keys.

In CircleCI, click go to your Project settings, and click Environment Variables on the left, and add these two environment variables with the appropriate values.

At this point you can call into Screenshotbot from your job.

Setting up Firebase test run

We assume you already set up running instrumentation tests on Firebase. (If you need help, feel free to contact us).

At this point you need to make sure your call into Firebase Test Lab also pulls all the screenshots that were generated during the run. In your .circleci/config.yml, you can use something like the following:

cd ~/project && sudo gcloud firebase test android run \
              --app ./build/outputs/apk/debug/project-debug.apk \
              --test ./build/outputs/apk/androidTest/debug/project-debug-androidTest.apk \
              --results-bucket cloud-test-${GOOGLE_PROJECT_ID} \
              --directories-to-pull /sdcard/screenshots/<package-name-of-instrumentation-apk> \
              --device-ids Pixel2 \
              --os-version-ids 27

Screenshotbot provides a script to process these screenshots:

curl https://screenshotbot.io/recorder-master.jar -o recorder.jar

You can now use the recorder.jar to upload the screenshots to Screenshotbot:

java -jar recorder.jar --dir ${CIRCLE_ARTIFACTS}/*/*/artifacts/screenshot_bundle.zip \
              --channel <channel-name> \
              --metadata ${CIRCLE_ARTIFACTS}/*/*/artifacts/metadata.xml \
              --is-production \
              --branch ${CIRCLE_BRANCH} \
              --api-key ${SCREENSHOTBOT_API_KEY} \
              --repo ${CIRCLE_REPOSITORY_URL} \
              --api-secret ${SCREENSHOTBOT_API_SECRET}

Choose the channel name appropriately, if you're using buck it could the the Buck target to the instrumentation test. If you're using multiple gradle repositories, it could be the Github URL to the gradle repository, etc. Each channel is monitored indepedently.

Full Example

Here's a full working example.