Integrate Your Test Suite with BrowserStack
BrowserStack’s JUnit SDK supports a plug-and-play integration. Run your entire test suite in parallel with a few steps!
Select your integration method
-
BrowserStack SDK (Recommended)
Plug-n-play solution that takes care of all the integration steps for you -
Legacy integration
Perform the integration step-by-step yourself (legacy flow)
Using the BrowserStack SDK is the recommended integration method for JUnit. The SDK auto-handles your integration steps.
Learn the benefits of using BrowserStack SDK
Following are the benefits of using BrowserStack SDK against manual integration process:
Integration step | With BrowserStack SDK | With manual integration |
---|---|---|
Connect to CDP Endpoint to run tests on BrowserStack |
![]() browserstack.yml config file |
![]() |
Integrate with BrowserStack Local |
![]() browserstack.yml config file |
![]() |
Send test context to BrowserStack for reporting |
![]() browserstack.yml config file |
![]() |
Use basic cross browser testing parallelization |
![]() browserstack.yml config file |
![]() |
Use advanced parallelization strategies |
![]() browserstack.yml config file |
![]() |
Prerequisites
- An existing automated test suite.
- Junit, Java v8+ is installed on your machine.
-
Maven is installed on your machine, Maven environment variables are set, and Maven bin is added to the system path,
$PATH
.
Looking for a starter project? Get started with our JUnit sample project
Integration steps
Based on the method you use to build your project, complete the steps in the following tabs to integrate with BrowserStack.
Set BrowserStack credentials
Save your BrowserStack credentials as environment variables. It simplifies running your test suite from your local or CI environment.
# Set these values in your ~/.zprofile (zsh) or ~/.profile (bash)
export BROWSERSTACK_USERNAME="YOUR_USERNAME"
export BROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY"
$env: BROWSERSTACK_USERNAME "YOUR_USERNAME"
$env: BROWSERSTACK_ACCESS_KEY "YOUR_ACCESS_KEY"
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
Maven Archetype provides a template to quickly configure your project.
Run the following command your terminal/command prompt to add browserstack-java-sdk
dependency and browserstack.yml
file in your project.
mvn archetype:generate -B -DarchetypeGroupId=com.browserstack \
-DarchetypeArtifactId=browserstack-sdk-archetype-integrate -DarchetypeVersion=1.2 \
-DgroupId=com.browserstack -DartifactId=browserstack-sdk-archetype-integrate -Dversion=1.2 \
-DBROWSERSTACK_USERNAME=YOUR_USERNAME -DBROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY \
-DBROWSERSTACK_FRAMEWORK=junit5
mvn archetype:generate -B -DarchetypeGroupId="com.browserstack" -DarchetypeArtifactId="browserstack-sdk-archetype-integrate" -DarchetypeVersion="1.2" -DgroupId="com.browserstack" -DartifactId="browserstack-sdk-archetype-integrate" -Dversion="1.2" -DBROWSERSTACK_USERNAME="YOUR_USERNAME" -DBROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY" -DBROWSERSTACK_FRAMEWORK="junit5"
Update your BrowserStack config file
When you install the SDK, a browserstack.yml
config file is created at the root level of your project. This file holds all the required capabilities to run tests on BrowserStack.
Specify platforms to test on
Set the browsers/OS you want to test under the platforms
object. Select over 100+ browsers-OS combinations from the list of supported browsers and OS
BrowserStack Reporting
You can leverage BrowserStack’s extensive reporting features using the following capabilities:
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 Automate or App Automate as Test Observability will automatically identify different build runs.
Restrict the characters in your projectName
and buildName
to alphanumeric characters (A-Z, a-z, 0-9), underscores (_), colons (:), and hyphens (-). Any other character will be replaced with a space.
sessionName
is the name of your test sessions and is automatically picked from your test class/spec name. It doesn’t need to be set manually when using the BrowserStack SDK.
Use additional debugging features
By default, BrowserStack provides prettified session logs, video recording on every failed command, and a video of the entire test. Additionally, you can enable the following features:
Update browserstack.yml file with selected capabilities
Copy the following code snippet and replace contents of browserstack.yml
file in the root folder of your test suite.
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY
framework: junit
platforms:
- os: OS X
osVersion: Ventura
browserName: chrome
browserVersion: latest
- os: Windows
osVersion: 10
browserName: playwright-firefox
browserVersion: latest
- os: OS X
osVersion: Monterey
browserName: playwright-webkit
browserVersion: latest
browserstackLocal: true
buildName: bstack-demo
projectName: BrowserStack Sample
CUSTOM_TAG_1: "You can set a custom Build Tag here"
# Use CUSTOM_TAG_<N> and set more build tags as you need.
debug: true
consoleLogs: info
Run your test suite
Run the following command from your root directory to run your test suite with BrowserStack.
mvn test
To find out the location of the BrowserStack SDK log files, refer to BrowserStack SDK Log Files. If you are looking for more information, see FAQ documentation.
Advanced features and use cases
Here’s a list of features and capabilities you may find useful.
Lighthouse Integration
Learn how to Integrate Lighthouse to your Playwright tests for improving the quality of your web pages.
Chrome Extension Testing
Learn more about Testing Chrome Extension on your Playwright tests with BrowserStack Automate.
Simulate IP geolocation
The browserstack.geoLocation
capability lets you test your websites across different countries.
Note that this capability is supported on the Enterprise plan only. You can contact sales to get an Enterprise plan for your account.
Capability | Description | Expected values |
---|---|---|
browserstack.geoLocation |
Set the country code you want your test to detect | A string. An ISO 2 country code FR for France, CN for China Check out the complete list of 45+ countries we support. |
browserstack.geoLocation: FR
Others
Following are a few additional links to documentation pages that might help with your test scenarios:
- Change the desktop browser window in your tests
- Test File upload scenarios
- Prevent sensitive test data from appearing in the Automate logs using mask commands
Next steps
Once you have successfully integrated your test suite with BrowserStack, you might want to check the following:
- Refer to the list of capabilities that you want to use in tests
- Find information about your Projects, Builds and Sessions using our REST APIs
- Set up your CI/CD: Gitlab, Azure Pipelines, CircleCI, GitHub Actions, Jenkins
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
- RESOURCES
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!