Skip to main content
No Result Found

Run accessibility checks on an Espresso sample repo

Try out app accessibility automation with the BrowserStack sample repository.

Prerequisites

  • Ensure you have a BrowserStack username and access key. Obtain your userName and accessKey from the Account & Profile section on the dashboard.
    If you have not yet created an account, sign up for a free trial.
  • 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 test suite (separate .apk file).
  • Ensure the following are installed on your system:
    • Java 11 or later.
    • AGP 7.3 or later.
    • API level 27 or higher.
    • Gradle 7 or later. Ensure you also change the Gradle wrapper properties.
    • Cucumber v4 + JUnit v4, or JUnit v4.

Currently, the BrowserStack SDK doesn’t support Espresso with the JUnit 5 Runner.

Run a sample build

Get the sample app and test suite

Upload the app

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

The following sample cURL command demonstrates 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/App.apk"

A sample response for the request is shown below:


{
    "app_name":"Application-debug.apk",
    "app_url":"bs://j3c874f852ea50957a3fdc33f47514288c4ba4",
    "app_version":"1.0",
    "app_id":"j3c874f852ea50957a3fdc33f47514288c4ba4",
    "uploaded_at":"2022-05-12 07:27:54 UTC",
    "expiry":"2022-06-11 07:27:54 UTC"
}

Use the app_id parameter to identify the application you want to test when you run Espresso tests.

App upload may take a few seconds to a minute, depending on the size of your app. Do not interrupt the cURL command until you get the response back.

Upload the test suite

Upload the Espresso test suite (.apk) file to the BrowserStack servers using a REST API request.

The following sample cURL command demonstrates 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 shown below:

{
    "test_suite_name":"Application-debug-test.apk",
    "test_suite_url":"bs://f7c874f21852ba57957a3e31f47514288c4ba4",
    "test_suite_id":"f7c874f21852ba57957a3e31f47514288c4ba4",
    "uploaded_at":"2022-05-12 07:32:41 UTC",
    "expiry":"2022-06-11 07:32:41 UTC",
    "framework":"espresso"
}

Use the test_suite_id parameter to identify the test suite when you run Espresso tests.

Run Espresso tests

In a cURL command, add the following parameters and send the API request to run the test.

  • app - specify the identifier of the application that you want to test. The app_id is generated when you upload the app to BrowserStack, see Step 6.
  • testSuite - specify the identifier of the Espresso test-suite you want to run. The test_suite_id is generated when you upload your test suite to BrowserStack, see Step 7.
  • devices - specify a list of Android devices on which you want to test your app. For more information, see Specify devices.
  • accessibility - enable accessibility checks.
  • In the API request, app, testSuite, and devices are mandatory parameters to start the test execution.
  • For a complete list of parameters that you can use in your Espresso test execution, see Espresso Build API reference.
curl -u "USERNAME:ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d "{
    \"app\": \"bs://$app_id\",
    \"testSuite\": \"bs://$test_suite_id\",
    \"devices\": ["Samsung Galaxy S24-14.0"]
    \"deviceLogs\": true,
    \"project\": \"$PROJECT_NAME\",
    \"accessibility\": true,
    }
}" \
-H "Content-Type: application/json"

A sample response for the request is shown:

{
    "message" : "Success",
    "build_id" : "4d2b4deb810af077dd98f479bfdd2e64f36c3"
}

The build_id uniquely identifies your build in App Automate. Each test build is an execution of the Espresso test suite on all selected devices.

If your tests fail with a NO TESTS RAN error, refer to the No tests ran guide.

View test results

After you run the test using the REST API, visit the App Automate dashboard to view your test results, debug logs, and overall test details.


Visit App Accessibility dashboard

You can also use API requests to view the 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