Get your setup working faster. Join our Discord for optimisation tips from elite testers.Join our Discord
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 testing to run accessibility checks on mobile apps, and view the reports on the App Accessibility dashboard.
By default, the BrowserStack SDK manages your test run. The SDK creates the Appium driver, uploads the app, and controls the session from browserstack.yml. If your tests already perform these tasks, see the Tests running on BrowserStack without SDK tab.
For Android devices, automated App Accessibility testing is supported on version 11 and above.
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.
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.
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 the browserstack.yml file to your project.
Replace the placeholder values with your BrowserStack credentials and the path to your app in the following commands.
The minimum supported browserstack-java-sdk version is 1.32.3.
The browserstack.yml file defines the required capabilities to run tests on BrowserStack. It is platform-specific and located in the corresponding platform folder (android/ or ios/). Make sure you modify the file that corresponds to your testing platform.
Open the browserstack.yml file.
Set your BrowserStack userName and accessKey.
Set your projectName and buildName.
Set the framework to junit4.
Set the accessibility flag to true. The default value is false.
Configure the accessibilityOptions property to set various accessibility testing options. For details, see Configuration options.
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.
Specify all the 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.
Use a non-SDK setup if your tests meet all of the following criteria:
You run your app tests on BrowserStack App Automate.
You use RemoteWebDriver or your own Appium client.
You manage your own app uploads and test capabilities.
You don’t want the BrowserStack SDK to manage the Appium driver or your session.
Prerequisites for a non-SDK setup
App Accessibility automated testing is enabled for the account running the tests.
BrowserStack SDK version 1.56.0 or later is installed in your project.
Configure your tests
Add the BrowserStack SDK
The BrowserStack SDK runs the accessibility scan and publishes the report, even in a non-SDK setup. Add the browserstack-java-sdk dependency to your pom.xml file:
The browserstack.yml file configures the BrowserStack SDK to scan your session without controlling your driver. Add all keys at the top level of the file, not under accessibilityOptions.
To configure the file, follow these steps:
Create or open the browserstack.yml file in the root directory of your project.
Set the userName and accessKey.
Set the framework to junit4.
Set browserstackAutomation to false. By default, the flag is set to true.
Set accessibility to true.
Add your app ID to app. If your tests already specify the app in their own capabilities and you don’t want to set an app ID in browserstack.yml, set skipAppOverride to true instead.
Save the file.
Set app or skipAppOverride. The BrowserStack SDK uses the app context to identify the session as a mobile app session and route it to App Accessibility. If you don’t have an app ID, you can add a placeholder value, because your driver, not the SDK, launches the app. If you set neither key, the SDK treats the session as a web session, and no App Accessibility report is generated.
The following configuration runs App Accessibility scans on a JUnit 4 suite. Your tests select the device through their own capabilities.
```yaml
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY
framework: junit4
browserstackAutomation: false # your tests keep control of the driver
accessibility: true # turns on App Accessibility scanning
app: bs://<app-id> # or use skipAppOverride: true
```
See the following sections to troubleshoot common errors with this setup:
Your build fails with a 403 error about your current plan
App Accessibility automated testing isn’t enabled or available for the account running the tests. Enable App Accessibility automated testing for that account, or upgrade your plan, and then run your build again.
If you’re not sure how to enable automated testing or upgrade your plan, contact BrowserStack Support.
The report appears under Web Accessibility, or no report is generated
The BrowserStack SDK treated your session as a web session instead of a mobile app session. This misrouting happens for either of the following reasons:
Your BrowserStack SDK is older than version 1.56.0 or missing. Install or upgrade the SDK to version 1.56.0 or later.
Neither app nor skipAppOverride is set in browserstack.yml. Set either key so the SDK routes the session to App Accessibility. If you don’t have the app ID, use a placeholder value to supply the app context. Your driver launches the app from your configured capabilities.
Your build fails with a 401 error for incorrect credentials
The userName or accessKey in browserstack.yml is incorrect. Obtain your credentials from the Account & Profile section and add them to the configuration file, then run your build again.
Scans appear in App Automate, but the report fails to generate
Your BrowserStack SDK version doesn’t support this setup. Upgrade the SDK to version 1.56.0 or later, then run your build again. If the report fails to generate even after you have upgraded the SDK, contact BrowserStack Support.
The Android report lists no issues even when the app has issues
The cause is unrelated to your browserstackAutomation configuration. Contact BrowserStack Support with a link to your build.