Upload JUnit XML reports to Test Observability
Quick start guide to upload your existing XML-formatted JUnit reports to BrowserStack Test Observability
JUnit XML reports have become the standard format for exchanging test results between tools. JUnit XML reports are not limited to Java and can be generated by many different testing frameworks for Java, JavaScript, Ruby, Python, or any other language.
You can upload your JUnit XML reports into Test Observability using our CLI tool (recommended) or by making a POST request to the designated upload API. Follow this doc to import your first JUnit XML report into Test Observability.
Integrate using JUnit XML reports only if you do not see your framework in the list of supported frameworks. Due to limitations on information JUnit XML reports can hold, certain features in Test Observability such as test execution video, will not be available when using JUnit XML reports as a data source.
Prerequisites
- BrowserStack Username and Access Key, which you can find in account settings. If you have not created an account yet, you can sign up for a Free Trial or purchase a plan.
- XML-formatted JUnit reports of the build run you want to upload.
Integrate with Test Observability using JUnit XML reports
Follow these steps to upload JUnit XML reports into Test Observability:
Prepare your JUnit XML reports for upload
Ensure that you have the JUnit XML files ready for import into Test Observability. Make sure the XML files comply with the required format and include all necessary test result information.
Here is a quick checklist to prepare your XML files:
- The file format is zip archive(containing multiple XML files and screenshots if available) or a single XML file.
- The XML file has a valid JUnit structure. Visit the API documentation for more details on supported XML schemas.
- The XML files belong to the same build run in case of multiple XML files.
Upload your JUnit XML reports
Using the CLI (Recommended)
Our CLI tool provides a simple way to upload your JUnit XML reports to Test Observability without having to use lengthy curl commands. It also automatically detects your CI and Git metadata for deeper integration.
1. Install the CLI
Navigate to your project’s root directory and install the CLI using the following command based on your operating system:
macOS Installation
Choose the appropriate command based on your Mac’s processor:
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=macos&os_arch=arm64" | bsdtar -xvf- -O > browserstack-cli && chmod 0775 browserstack-cli
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=macos&os_arch=x64" | bsdtar -xvf- -O > browserstack-cli && chmod 0775 browserstack-cli
Linux Installation
Choose the appropriate command based on your Linux distribution and architecture:
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=linux&os_arch=x64" | tar -xz -O > browserstack-cli && chmod +x browserstack-cli
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=linux&os_arch=arm64" | tar -xz -O > browserstack-cli && chmod +x browserstack-cli
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=alpine&os_arch=arm64" | tar -xz -O > browserstack-cli && chmod +x browserstack-cli
Windows Installation
Run the following PowerShell commands to install the CLI:
Invoke-WebRequest -Uri "http://api.browserstack.com/sdk/v1/download_cli?os=windows&os_arch=x64" -OutFile browserstack-cli.zip
Expand-Archive -Path browserstack-cli.zip -DestinationPath . -Force
Rename-Item -Path "binary-windows-x64.exe" -NewName "browserstack-cli.exe"
Remove-Item browserstack-cli.zip # Cleanup
2. Create the browserstack.yml file
userName: BROWSERSTACK_USERNAME
accessKey: BROWSERSTACK_ACCESS_KEY
projectName: Your Project Name
buildName: JUnit Reports Upload
CUSTOM_TAG_1: Regression
CUSTOM_TAG_2: P0
# Use CUSTOM_TAG_<N> and set more build tags as you need.
testObservabilityOptions:
reportPath: /path/to/your/junit-reports
format: junit
Replace BROWSERSTACK_USERNAME
and BROWSERSTACK_ACCESS_KEY
with your BrowserStack credentials, and update the reportPath
to point to your JUnit XML reports directory or zip file.
3. Upload your test results
Run the following command to upload your test results:
macOS Commands
# Basic usage
./browserstack-cli upload-report
# Advanced usage with explicit parameters
./browserstack-cli upload-report --browserstackConfigFile="path/to/browserstack.yml" --reportPath="path/to/junit-reports" --reportFormat="junit"
Linux Commands
# Basic usage
./browserstack-cli upload-report
# Advanced usage with explicit parameters
./browserstack-cli upload-report --browserstackConfigFile="path/to/browserstack.yml" --reportPath="path/to/junit-reports" --reportFormat="junit"
Windows Commands
# Basic usage
.\browserstack-cli.exe upload-report
# Advanced usage with explicit parameters
.\browserstack-cli.exe upload-report --browserstackConfigFile="path\to\browserstack.yml" --reportPath="path\to\junit-reports" --reportFormat="junit"
Note that the parsing of the uploaded XML files happens asynchronously and hence it might take a few seconds for the results to be available on Test Observability after the API request is made.
For more detailed information about the CLI, visit the Report Upload CLI documentation.
Using the API
You can upload your JUnit XML reports by making a POST request to the Test Observability API endpoint.
Make a POST API request
Make a POST request to https://upload-observability.browserstack.com/upload
to upload the JUnit XML reports. Ensure to:
- Provide the path to the XML file or a zip archive to be uploaded.
- Populate the input parameter values according to your requirements. You can find the exhaustive list of supported API parameters and their use in the API documentation.
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -vvv \
-X POST \
-F "data=@/Users/testUser/junit_report.xml" \
-F "projectName=Junit report uploads" \
-F "buildName=Observability Sample" \
-F "buildIdentifier=Sample Build Identifier" \
-F "tags=junit_upload, regression" \
-F "ci=http://localhost:8080/" \
-F "frameworkVersion=mocha, 10.0.0" \
https://upload-observability.browserstack.com/upload
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -vvv ^
-X POST ^
-F "data=@C:\Users\testUser\junit_report.xml" ^
-F "projectName=Junit report uploads" ^
-F "buildName=Observability Sample" ^
-F "buildIdentifier=Your Build Identifier" ^
-F "tags=junit_upload, regression" ^
-F "ci=http://localhost:8080/" ^
-F "frameworkVersion=mocha, 10.0.0" ^
https://upload-observability.browserstack.com/upload
To learn more about the upload API you can visit the API documentation.
Note that the parsing of the uploaded XML files happens asynchronously and hence it might take a few seconds for the results to be available on Test Observability after the API request is made.
Visit Test Observability
Voila! It’s done, upon successful execution of the upload, you receive a success state in the response along with a URL to the uploaded build. You can then visit the URL to analyze and gain insights from the imported test results. Alternatively, you can also navigate to your build run using Build Runs.
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
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!