Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy
No Result Found

Run your first test

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 will help you run your first Espresso test on BrowserStack.

1. Setup

  1. You will need a BrowserStack username and access key. To obtain your access credentials, sign up for a free trial or purchase a plan.

  2. Espresso tests are built into a separate apk file from your app. Hence, you will need access to both the app (.apk or .aab) and the Espresso test suite (separate .apk file).

Note: 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.

2. Upload your app

Upload your Android app (.apk or .aab file) to BrowserStack servers using a REST API request.

The following sample cURL command shows how to upload an app:

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 Espresso tests.

Note: 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.

3. 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 Espresso tests.

4. 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:

Select device
This device is not available in the free plan. Please upgrade to paid plan.
 

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.

5. 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.

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy Check Circle