Skip to main content
No Result Found

Integrate Espresso test suite with app accessibility testing

Learn how to add accessibility checks to your existing functional tests and generate comprehensive reports of accessibility issues.

BrowserStack App Accessibility supports Espresso testing on a wide range of real Android devices. You can integrate your existing functional test suites with App Accessibility Automate to run accessibility checks on your mobile apps and access the generated accessibility violation reports on the App Accessibility dashboard.

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.
  • Ensure you have a functional Espresso test suite. To set one up, see Run accessibility checks on a sample repo.
  • 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.

Integrate App Accessibility Automate to run accessibility checks

Add mavenCentral and the classpath for Android Tools

In the root build.gradle file of your project, add mavenCentral under buildscript at the root level and the classpath for android tools under dependencies.

buildscript {
    repositories {
        ...
        mavenCentral()
    }
    dependencies {
        ...
        classpath 'com.android.tools.build:gradle:<AGP_version>'
        classpath 'com.browserstack:gradle-tool:1.0.0'
    }
}

Add the Gradle plugin and the SDK dependency

In your project’s app directory, open the app’s build.gradle file and add the Gradle plugin under plugins and the BrowserStack SDK dependency under dependencies.

plugins {
 id 'com.browserstack.gradle-tool'
 }
dependencies {
 androidTestImplementation group: 'com.browserstack', name: 'browserstack-java-sdk', version: '1.21.0'
}

Enable internet access for the app

Open your app’s AndroidManifest.xml file and add the following entries. These entries allow the test app to connect to the internet and use the HTTP protocol to send performScan requests.

    <uses-permission android:name="android.permission.INTERNET"/>

      <application
        android:usesCleartextTraffic="true"
        ...
    </application>

Upload your app

Upload your Android 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"
}

The app_id parameter is used to identify the application you want to test when you run Espresso tests.

App upload can take from 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 the BrowserStack servers using REST API.

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"
}

The test_suite_id parameter is used 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 1.
  • testSuite - specify the Espresso test suite uploaded to BrowserStack. The test_suite_id is generated when you upload your test suite to BrowserStack. See Step 2.
  • 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.
  • accessibilityOptions - Configure the accessibilityOptions parameter to set various accessibility testing options. For a list of available accessibility options that you can use to configure your tests, see Configuration options.
  • 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 S24-14.0"], ["Google Pixel 8-14.0"], ["Samsung S21-11.0"]
    \"deviceLogs\": true,
    \"project\": \"$PROJECT_NAME\",
    \"accessibility\": true,
    \"accessibilityOptions\": {
        \"wcagVersion\": \"wcag21aa\",
        \"includeIssueType\": {
            \"bestPractice\": true,
            \"needsReview\": false
        },
        \"includeTagsInTestingScope\": [\"TAG_1\"],
        \"excludeTagsInTestingScope\": [\"TAG_2\"]
    }
}" \
-H "Content-Type: application/json"

Response

A sample response to the above API request is shown below :

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

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

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

View test results

After you run the test using the REST API, visit the App Automate dashboard to view your test results, debugging 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