JUnit-XML/BDD-JSON based report upload
Project Setup
Step 1: Java must be installed:
Run this command in terminal to check if java is already installed:
javac --version
Use this link to install Java (JDK) if not present already - https://docs.oracle.com/en/java/javase/16/install/installation-jdk-macos.html
Step 2: Maven must be installed:
Run this command in terminal to check if maven is already installed:
mvn --version
Run this command in terminal if maven not present already
brew install maven
mvn --version
Step 3: Go to project repository
Check out your codebase from your repository (example Git).
You can also refer to this example project.
Create and export report via Jenkins
Pre-requisite
- Jenkins must be installed (this is applicable for other CI/CD tools like Travis CI, Circle CI, GitHub Actions, Bamboo CI).
- A jenkins pipline for CI/CD process exists.
Step 1: Modify changes in “Jenkinsfile”
- Go to code base.
- Open root folder and verify if Jenkinsfile exists.
- If not create one (for references refer to this link).
- Add this code in Jenkinsfile to make it paramaterized build and upload the report:
. . . agent any parameters { string(name: 'TEST_MANAGEMENT_API_TOKEN', defaultValue: '*************28a42', description: 'API Token of your Test Management Account - You can find here: https://test-management.browserstack.com/settings') string(name: 'TEST_MANAGEMENT_PROJECT_NAME', defaultValue: 'Project Name', description: 'Project Name where you want to upload test results, NOTE: If any new project name is defined, Test Management will create a project for you') string(name: 'TEST_RUN_NAME', defaultValue: 'Test Run - $BUILD_NUMBER', description: 'Name of your Test Run') string(name: 'USER_EMAIL', defaultValue: 'test.management23@gmail.com', description: 'User Email') } . . . stages{ . . . stage('Upload Reports in Test Management') { steps { sh ''' export JUNIT_XML_FILE_PATH="<report path>" curl -k -X POST https://test-management.browserstack.com/api/v1/import/results/xml/junit \ -H "API-TOKEN:$TEST_MANAGEMENT_API_TOKEN" \ -F project_name="$TEST_MANAGEMENT_PROJECT_NAME" \ -F "file_path=@$JUNIT_XML_FILE_PATH" \ -F test_run_name="$TEST_RUN_NAME" \ -F user_email=$USER_EMAIL ''' } } . . . } . . .
- Add this code in Jenkinsfile to make it non-parameterized reports upload:
stage('Upload Reports in Test Management') {
steps {
sh '''
export TEST_MANAGEMENT_API_TOKEN="<API Token>"
export TEST_MANAGEMENT_PROJECT_NAME="<Project Name>"
export JUNIT_XML_FILE_PATH="<Reports Path>"
export TEST_RUN_NAME="<Test Run Name>"
export USER_EMAIL="<email-address>"
curl -k -X POST https://test-management.browserstack.com/api/v1/import/results/xml/junit \
-H "API-TOKEN:$TEST_MANAGEMENT_API_TOKEN" \
-F project_name="$TEST_MANAGEMENT_PROJECT_NAME" \
-F "file_path=@$JUNIT_XML_FILE_PATH" \
-F test_run_name="$TEST_RUN_NAME" \
-F user_email=$USER_EMAIL
'''
}
}
Note: Replace the “<….>” as per your requirements. You can also configure this as build with parameters. The example for this is avaialble in sample Jenkinfile.
Step 2: Push the codebase into Github
Step 3: Go to Jenkins CI/CD tool
Step 4: Go to Project pipeline and click on Build Now
Step 5: Wait for build to complete successfully
This build will generate test reports which shall be of following formats
JUnit-XML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by org.testng.reporters.JUnitReportReporter -->
<testsuite hostname="HarshAgarwal-FVFHG5HGQ05D" failures="1" tests="8" name="com.browserstack.BStackDemoTest" time="127.157" errors="1" timestamp="2023-03-06T16:02:53 IST" skipped="1">
<testcase classname="com.browserstack.BStackDemoTest" name="logoutFromBstackDemo" time="14.590"/>
<system-out/>
<testcase classname="com.browserstack.BStackDemoTest" name="visitBStackDemo" time="16.022"/>
<system-out/>
<testcase classname="com.browserstack.BStackDemoTest" name="makePayment" time="32.323"/>
<system-out/>
<testcase classname="com.browserstack.BStackDemoTest" name="placeOrder" time="17.422"/>
<system-out/>
<testcase classname="com.browserstack.BStackDemoTest" name="addDuplicateProductToCart" time="16.562"/>
<system-out/>
</testsuite> <!-- com.browserstack.BStackDemoTest -->
BDD-JSON
[
{
"line": 1,
"elements": [
{
"start_timestamp": "2023-03-01T11:54:13.014Z",
"before": [
{
"result": {
"duration": 7501927000,
"status": "passed"
},
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.setUp()"
}
}
],
"line": 4,
"name": "Add product to cart",
"description": "",
"id": "browserstack-demo;add-product-to-cart",
"after": [
{
"result": {
"duration": 4801484000,
"status": "passed"
},
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.teardown(io.cucumber.java.Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 4991854000,
"status": "passed"
},
"line": 5,
"name": "I am on the website \u0027https://www.bstackdemo.com\u0027",
"match": {
"arguments": [
{
"val": "https://www.bstackdemo.com",
"offset": 21
}
],
"location": "com.browserstack.stepdefs.StackDemoSteps.I_am_on_the_website(java.lang.String)"
},
"keyword": "Given "
},
{
"result": {
"duration": 2793153000,
"status": "passed"
},
"line": 6,
"name": "I select a product and click on \u0027Add to cart\u0027 button",
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.I_select_a_product_and_add_to_cart()"
},
"keyword": "When "
},
{
"result": {
"duration": 484470000,
"status": "passed"
},
"line": 7,
"name": "the product should be added to cart",
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.product_should_be_added_to_cart()"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@TC-1"
}
]
},
{
"start_timestamp": "2023-03-01T11:54:33.624Z",
"before": [
{
"result": {
"duration": 4557681000,
"status": "passed"
},
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.setUp()"
}
}
],
"line": 10,
"name": "Add product to cart",
"description": "",
"id": "browserstack-demo;add-product-to-cart",
"after": [
{
"result": {
"duration": 4530752000,
"status": "passed"
},
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.teardown(io.cucumber.java.Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 7366664000,
"status": "passed"
},
"line": 11,
"name": "I am on the website \u0027https://www.bstackdemo.com\u0027",
"match": {
"arguments": [
{
"val": "https://www.bstackdemo.com",
"offset": 21
}
],
"location": "com.browserstack.stepdefs.StackDemoSteps.I_am_on_the_website(java.lang.String)"
},
"keyword": "Given "
},
{
"result": {
"duration": 2400782000,
"status": "passed"
},
"line": 12,
"name": "I select a product and click on \u0027Add to cart\u0027 button",
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.I_select_a_product_and_add_to_cart()"
},
"keyword": "When "
},
{
"result": {
"duration": 364539000,
"status": "passed"
},
"line": 13,
"name": "the product should be added to cart",
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.product_should_be_added_to_cart()"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@TC-2"
}
]
},
{
"start_timestamp": "2023-03-01T11:54:52.856Z",
"before": [
{
"result": {
"duration": 5952046000,
"status": "passed"
},
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.setUp()"
}
}
],
"line": 15,
"name": "Add product to cart",
"description": "",
"id": "browserstack-demo;add-product-to-cart",
"after": [
{
"result": {
"duration": 4417609000,
"status": "passed"
},
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.teardown(io.cucumber.java.Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 4671009000,
"status": "passed"
},
"line": 16,
"name": "I am on the website \u0027https://www.bstackdemo.com\u0027",
"match": {
"arguments": [
{
"val": "https://www.bstackdemo.com",
"offset": 21
}
],
"location": "com.browserstack.stepdefs.StackDemoSteps.I_am_on_the_website(java.lang.String)"
},
"keyword": "Given "
},
{
"result": {
"duration": 2434313000,
"status": "passed"
},
"line": 17,
"name": "I select a product and click on \u0027Add to cart\u0027 button",
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.I_select_a_product_and_add_to_cart()"
},
"keyword": "When "
},
{
"result": {
"duration": 325711000,
"status": "passed"
},
"line": 18,
"name": "the product should be added to cart",
"match": {
"location": "com.browserstack.stepdefs.StackDemoSteps.product_should_be_added_to_cart()"
},
"keyword": "Then "
}
]
}
],
"name": "BrowserStack Demo",
"description": "",
"id": "browserstack-demo",
"keyword": "Feature",
"uri": "file:src/test/resources/features/test/StackDemo.feature",
"tags": []
}
]
Step 6: View test run report in Test Management
- Select project to which test report was exported
- Click Test Runs menu link
- Open the Test Run generated from automation test exectution
- You will find all the test cases with their respective results here
cURL
command until you get the response back.
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!