Skip to main content
No Result Found

Integrate Junit 4 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 supports out-of-the-box integration with JUnit 4. You can integrate your existing functional test suites with App Accessibility Automate to run accessibility checks on mobile apps. You can access the generated accessibility violation reports on the App Accessibility dashboard.

For Android devices, App Accessibility automated tests are supported on version 11 and above.

Prerequisites

  • Ensure you have a BrowserStack Username and Access Key. Obtain your username and access key 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 JUnit 4 test suite. To set one up, see Run accessibility checks on a sample repo.
  • Java 8 or higher is installed on your system.
  • If you use the CLI to run tests, make sure that Apache Maven is installed on your system, the Maven environment variables are set, and the Maven bin directory is added to the system path ($PATH) if you are using macOS or Linux systems.
  • Appium is installed on your system.

Integrate App Accessibility Automate to run accessibility checks

Integrate BrowserStack App Accessibility with your test suite.

Set your BrowserStack credentials

Save your BrowserStack credentials as environment variables to simplify running your test suite from your local or CI environment.

Set the following values in either your Zsh (~/.zprofile) or Bash (~/.profile) shell conifguration file.

export BROWSERSTACK_USERNAME=YOUR_USERNAME
export BROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY

In your terminal or command-line prompt, enter the following command:

setx BROWSERSTACK_USERNAME "YOUR_USERNAME"
setx BROWSERSTACK_ACCESS_KEY "YOUR_ACCESS_KEY"
set BROWSERSTACK_USERNAME=YOUR_USERNAME
set BROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY

Install BrowserStack SDK using Maven archetype

Run the following command in your terminal or command-line to add the browserstack-java-sdk dependency and browserstack.yml file to your project.
Replace the placeholder values with your BrowserStack credentials and the path to your app in the following commands.

mvn archetype:generate -B -DarchetypeGroupId=com.browserstack \
-DarchetypeArtifactId="browserstack-sdk-archetype-setup" -DarchetypeVersion=1.1 \
-DgroupId=com.browserstack -DartifactId=junit-appium-app-browserstack -Dversion=1.0 \
-DBROWSERSTACK_USERNAME=YOUR_USERNAME -DBROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY -DBROWSERSTACK_PROJECT_REPO=junit-appium-app-browserstack/junit-4:sdk
mvn archetype:generate -B -DarchetypeGroupId="com.browserstack" -DarchetypeArtifactId="browserstack-sdk-archetype-setup" -DarchetypeVersion="1.1" -DgroupId="com.browserstack" -DartifactId="junit-appium-app-browserstack" -Dversion="1.0" -DBROWSERSTACK_USERNAME="YOUR_USERNAME" -DBROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY" -DBROWSERSTACK_PROJECT_REPO="junit-appium-app-browserstack/junit-4:sdk"

Based on your test platform, navigate to the appropriate platform directory.

Copy icon Copy
Copy icon Copy

Set up the dependencies

The JUnit 4 dependency is already included in the BrowserStack sample repository. If it is not set, add the following dependency to the pom.xml file in the Android or iOS directory, based on your test platform:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version>
</dependency>

Modify the BrowserStack configuration file

The browserstack.yml file contains the required capabilities to run your tests on BrowserStack. It is located in your project’s root directory and is included in the downloaded sample.
This file is platform-specific. Make sure you update the file that corresponds to your test platform (Android or iOS).

  1. Open the browserstack.yml file.
  2. Set your BrowserStack userName and accessKey.
  3. Set your projectName and buildName.
  4. Set the framework:
    • Set it to junit4 if you want to run only JUnit 4 tests.
    • Set it to cucumber-junit4 if you want to run Cucumber tests using JUnit 4 as the test runner.
  5. Set the accessibility flag to true. By default, the flag is set to false.
  6. Configure the accessibilityOptions property to set various accessibility testing options. For details, see Configuration options.
  7. Add the relative or absolute path of the app you want to test in the app property. For example, app: ./examples/BStackSampleApp.apk. You can upload an Android app (.apk or .aab file) or an iOS app (.ipa file) from your local filesystem.
  8. Specify all device, OS, and OS version combinations that you want to test in the platforms section.

The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack App Automate since Automated tests will automatically identify different build runs.

browserstack.yml
Copy icon Copy

Run the sample test

From your platform folder (Android or iOS), run the following command:

Run an Android test
Copy icon Copy
Run an iOS test
Copy icon Copy

View the Accessibility test report

After the test completes, view the report in your project folder on the App Accessibility dashboard.


Visit App Accessibility dashboard

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