Espresso Testing
TestingBot provides access to Android physical devices and Android emulators, capable of running your Android Espresso tests.
Espresso is a mobile automation framework from Google, designed to run UI tests for Android applications.
Using Espresso in combination with TestingBot's Android cloud service is very straightforward:
- Upload your native mobile Android app, together with the Espresso test apk file. These are created with either Java or Kotlin.
- Specify on which devices you want to run the Espresso tests.
- Retrieve the results of the Espresso tests.
Getting Started
To get started, please follow the steps below:
-
You will need a
keyandsecretto connect to the TestingBot grid.
These credentials are available in the TestingBot member area. -
Espresso tests require a separate
apkfile for testing. So you will need to upload both the app (.apkor.aabfile) and the test file (.apk).
You can also use the TestingBot Espresso Demo App to give the Espresso Cloud Testing functionality a try.
TestingBot CLI
The easiest way to run Espresso tests on TestingBot is using our CLI tool. It handles uploading your app, test APK, and running tests in a single command.
Installation
npm install -g @testingbot/cli
Authentication
Authenticate using this command:
testingbot login
This opens your browser for authentication. After logging in, your credentials are saved to ~/.testingbot and you can start using the CLI.
Other Authentication Methods
-
Command-line options:
--api-keyand--api-secret -
Environment variables:
TB_KEYandTB_SECRET -
Config file: Create
~/.testingbotwith contentkey:secret
Quick Start
Run Espresso tests with a single command:
testingbot espresso app.apk app-test.apk --device "Pixel 8" --platform-version "14"
testingbot espresso app.apk app-test.apk --device "Samsung Galaxy S24" --real-device
The CLI will:
- Upload your app APK to TestingBot
- Upload your test APK
- Start the test run
- Show real-time progress and results
Upload Android App
To run Android Espresso tests on TestingBot, you will first have to upload your .apk or .aab file to TestingBot Storage.
When using the CLI, the app upload is handled automatically as part of the testingbot espresso command. Simply specify your app APK file as the first argument:
testingbot espresso /path/to/app/Application-debug.apk /path/to/test/Application-debug-test.apk --device "Pixel 8"
Alternatively, you can use the --app option:
testingbot espresso --app /path/to/app/Application-debug.apk --test-app /path/to/test/Application-debug-test.apk --device "Pixel 8"
curl -u api_key:api_secret \
-X POST "https://api.testingbot.com/v1/app-automate/espresso/app" \
-F "file=@/path/to/app/file/Application-debug.apk"
The API response will include an id response, which you can use in the other API calls.
{
"id": 4012
}
Upload Espresso Test Suite
You can now upload the .apk file containing the Espresso tests.
The upload process is similar to the app upload process.
When using the CLI, the test APK upload is handled automatically. Specify your test APK as the second argument:
testingbot espresso app.apk app-test.apk --device "Pixel 8"
Or use the --test-app option:
testingbot espresso --app app.apk --test-app app-test.apk --device "Pixel 8"
curl -u api_key:api_secret \
-X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/tests" \
-F "file=@/path/to/app/file/Application-debug-test.apk"
Replace the :id with the identifier you received during the app upload call.
Specify devices
You can specify one or more Android device capabilities with your API call.
These capabilities can target either Android emulators, or physical Android devices.
We offer special parameters which you can use to allocate a device:
| Regex Input | Result |
|---|---|
"Pixel.*" |
This will allocate any available Pixel device (phone) |
"*" |
This will allocate a random available Android device |
"Samsung [20-21]" |
This will allocate either an Samsung 20 or 21 |
Some Examples:
// find any Samsung Galaxy, except 23
-d '{"capabilities":[{"deviceName":"^(Galaxy.*)(?!23)$", "platformName":"Android", "realDevice": true}]}'
// find any device which name starts with Pixel
-d '{"capabilities":[{"deviceName":"Pixel.*", "platformName":"Android", "realDevice": true}]}'
Tablet Only
You can specify the tabletOnly capability when you only want to allocate a tablet device.
Phone Only
You can specify the phoneOnly capability when you only want to allocate a phone device.
-d '{"capabilities":[{"deviceName":"*", "tabletOnly": true, "platformName":"Android", "realDevice": true}]}'
-d '{"capabilities":[{"deviceName":"*", "phoneOnly": true, "platformName":"Android", "realDevice": true}]}'
Run Espresso Tests
Now that you have uploaded both your Android application and the Espresso test suite, you can run your first Espresso test on the TestingBot cloud.
Use the CLI to run tests with device selection options:
# Basic usage with device selection
testingbot espresso app.apk app-test.apk --device "Pixel 8" --platform-version "14"
# Real device
testingbot espresso app.apk app-test.apk --device "Samsung Galaxy S24" --real-device
# With test name and build identifier
testingbot espresso app.apk app-test.apk \
--device "Pixel 8" \
--platform-version "14" \
--name "Smoke Tests" \
--build "v2.1.0"
Device Options
| Option | Description |
|---|---|
--device <name> |
Device name (e.g., "Pixel 8", "Samsung.*") |
--platform-version <version> |
Android version (e.g., "12", "13", "14") |
--real-device |
Use a real device instead of emulator |
--tablet-only |
Only allocate tablet devices |
--phone-only |
Only allocate phone devices |
Test Filtering
# Run specific test classes
testingbot espresso app.apk app-test.apk \
--device "Pixel 8" \
--class "com.example.LoginTest,com.example.HomeTest"
# Run tests with specific annotations
testingbot espresso app.apk app-test.apk \
--device "Pixel 8" \
--annotation "com.example.SmokeTest" \
--size "small,medium"
# Exclude specific test classes
testingbot espresso app.apk app-test.apk \
--device "Pixel 8" \
--not-class "com.example.SlowTest"
Test Filtering Options
| Option | Description |
|---|---|
--class <classes> |
Run tests in specific classes (comma-separated fully qualified names) |
--not-class <classes> |
Exclude tests in specific classes |
--package <packages> |
Run tests in specific packages (comma-separated) |
--not-package <packages> |
Exclude tests in specific packages |
--annotation <annotations> |
Run tests with specific annotations (comma-separated) |
--not-annotation <annotations> |
Exclude tests with specific annotations |
--size <sizes> |
Run tests by size: small, medium, large (comma-separated) |
Network & Location
# With network throttling and geolocation
testingbot espresso app.apk app-test.apk \
--device "Pixel 8" \
--throttle-network "3G" \
--geo-location "DE" \
--language "de"
curl -u api_key:api_secret \
-X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
-d '{"capabilities":[{"platform":"ANDROID", "version":12, "deviceName":"Pixel 6", "platformName":"Android"}]}' \
-H "Content-Type: application/json"
Replace the :id with the identifier you received during the app upload call.
The API response will include a success response, indicating if the tests will start or if an error occurred.
{
"success": true
}
View Espresso Test Results
You will now see a test appear in the TestingBot dashboard, together with a video, test logs and other metadata.
You can also use the CLI or an API call to get the results from the run(s):
By default, the CLI waits for test completion and displays real-time progress:
testingbot espresso app.apk app-test.apk --device "Pixel 8"
The CLI will show:
- Upload progress for app and test APK
- Device allocation status
- Live output from Espresso tests
- Final pass/fail status
Async Mode
Use --async to start tests without waiting for results:
testingbot espresso app.apk app-test.apk --device "Pixel 8" --async
Download JUnit Report
Download the JUnit report after test completion:
testingbot espresso app.apk app-test.apk --device "Pixel 8" \
--report junit \
--report-output-dir ./reports
curl -u api_key:api_secret \
"https://api.testingbot.com/v1/app-automate/espresso/:id"
Replace the :id with the identifier you received during the app upload call.
The API response will include a response indicating the current state of the Espresso test results.
{
"runs": [
{
"status": "DONE",
"capabilities": {
"version": "12",
"deviceName": "Pixel 6",
"platformName": "Android"
},
"success": false,
"test": {
"sessionId": "30f6eild082c3-804f3c0ec2df-a18b2d431ffb-169920992163-48455547",
"environment": {
"name": "chrome",
"os": "Pixel 6 - 12.0",
"version": "12.0"
}
}
}
],
"version": "1.0"
}