Run your first automated app test using Espresso
Learn how to run your first test using Espresso on BrowserStack App Automate. Access the test results on the App Automate dashboard or use our REST API.
Espresso is a mobile automation framework provided by Google that helps you write UI tests for your Android applications. BrowserStack App Automate supports Espresso testing on a wide range of real Android devices. This guide helps you run your first Espresso test on BrowserStack.
Prerequisites
-
A BrowserStack
usernameandaccess key. To obtain your access credentials, sign up for a free trial or purchase a plan. -
Espresso tests are built into a separate
apkfile from your app. Hence, you need access to both the app (.apkor.aab) and the Espresso test suite (separate.apkfile).
If you do not have .apk files and want to try App Automate, you can download our sample Calculator app and Calculator test suite. Alternatively, check out our Espresso sample GitHub repository.
Follow these steps to run your first Espresso test on BrowserStack:
Upload your app
Upload your Android app (.apk or .aab file) to BrowserStack servers using any of the following methods:
Upload app using the App Automate dashboard
On the App Automate dashboard, click the Upload button on the top-right corner. Select the Android app (.apk or .aab file) you want to upload from your filesystem.

Upload app using App Management UI
To upload an app using the App Management UI, follow these steps:
-
On the App Automate dashboard, go to the sidebar and click App Management.
-
On the App Management UI, click Upload App.
-
Select the Android app (
.apkor.aabfile) you want to upload from your filesystem. To upload using a public URL, paste the URL of your app in the or upload from URL box. -
After selecting the app, choose the App Automate framework you want to use for testing. You can optionally add flags and a custom ID.
-
Click Upload. The app is uploaded to the BrowserStack servers. You’ll receive an App ID, which you can use to run tests.
To view your uploaded apps, apply the My Apps filter.

Upload app using REST API
Upload an Android app (.apk or .aab file) from your filesystem or a public URL using the REST API. The following sample cURL command uploads an app from your filesystem:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/app" \
-F "file=@/path/to/app/file/Application-debug.apk"
A sample response for the request is as follows:
{
"app_name":"Application-debug.apk",
"app_url":"bs://j3c874f21852ea50957a3fdc33f47514288c4ba4",
"app_version":"1.0",
"app_id":"j3c874f21852ea50957a3fdc33f47514288c4ba4",
"uploaded_at":"2022-05-12 07:27:54 UTC",
"expiry":"2022-06-11 07:27:54 UTC"
}
The value of the app_url parameter in the response is used to specify the application under test when you run your Espresso tests.
App upload will take a few seconds to about a minute, depending on the size of your app. Do not interrupt the curl command until you get the response back.
Upload your test suite
Upload your Espresso test suite (.apk) file to BrowserStack servers using our REST API.
The following sample cURL command shows how to upload a test suite:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/test-suite" \
-F "file=@/path/to/app/file/Application-debug-test.apk"
A sample response for the request is as follows:
{
"test_suite_name":"Application-debug-test.apk",
"test_suite_url":"bs://f7c874f21852ba57957a3fde31f47514288c4ba4",
"test_suite_id":"f7c874f21852ba57957a3fde31f47514288c4ba4",
"uploaded_at":"2022-05-12 07:32:41 UTC",
"expiry":"2022-06-11 07:32:41 UTC",
"framework":"espresso"
}
The value of the test_suite_url parameter in the response is used to specify the test suite when you run your Espresso tests.
To execute tests on devices, refer to the Custom Device Lab using Espresso documentation.
Execute Espresso tests
After you upload your app and test suite to BrowserStack servers, send an API request to start the test execution as shown in the following sample cURL request:
A sample response for the request is as follows:
{
"message": "Success",
"build_id": "4d2b4deb810af077d5aed98f479bfdd2e64f36c3"
}
The build_id is used to uniquely identify your build in App Automate.
If a test run stops due to a crash, you can stop the build by clicking Stop Build on the App Automate dashboard or using the REST API.
View test results
After you start an Espresso test suite execution using the REST API, visit your App Automate dashboard to view your test results, debugging logs, and overall test details.
You can also use API requests to view test results.
To integrate BrowserStack Test Reporting & Analytics with Espresso, see Test Reporting & Analytics on Espresso.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!