Skip to main content
No Result Found
Connect & Get help from fellow developers on our Discord community. Ask the CommunityAsk the Community

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 testing to run accessibility checks on your mobile apps. You can access the generated accessibility violation reports on the App Accessibility dashboard.

For Android devices, automated App Accessibility testing is supported on version 11 and above.

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. Therefore, you need access to both the app file (.apk or .aab) and the test suite file (.apk).
  • Make sure the following are installed on your system:
    • Java 11 or later.
    • Android Gradle Plugin (AGP) 7.3 or later.
    • API level 27 or higher.
    • Gradle 7 or later. Make sure you also change the Gradle wrapper properties in your project’s gradle-wrapper.properties file.
    • Cucumber v4 with JUnit v4, or only 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() in the repositories block within the buildscript block, and add the classpath for Android tools in the dependencies block.

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 BrowserStack Gradle plugin in the plugins block, and the BrowserStack SDK dependency in the dependencies block.

The minimum supported BrowserStack SDK version is 1.31.0.

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

Use the app_id parameter to identify the application 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"
}

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

Run Espresso tests

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

  • app: specify the app_id, which is the unique identifier of the application that you want to test. The app_id is generated when you upload the app to BrowserStack, see Upload your app.
  • testSuite: specify the test_suite_id, which is the unique identifier of the test suite you want to run. The test_suite_id is generated when you upload your test suite to BrowserStack, see Upload your test suite.
  • 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 for the 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