Skip to main content

CI/CD Integration

Import report via Jenkins

Pre-requisite

  1. A Jenkins pipeline has already been created.
  2. A Project has been created in Test Management.

Step 1: Modify or create a “Jenkinsfile” in your code

  1. Go to code base.
  2. Open root folder and verify if Jenkinsfile exists.
  3. If not create one (use this link for reference).
  4. Copy the code below as per the preferered option:
.
.
.
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
            '''
        }
    }
    .
    .
    .
}
.
.
.
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 “<….>” as per your own configuration value.

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

<?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 -->
[
  {
    "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": []
  }
]

Import report via Azure DevOps

Pre-requisite

  1. An Azure pipeline has already been created.
  2. A Project has been created in Test Management.

Step 1: Modify azure-pipelines.yml file

  1. Open Azure pipeline.
  2. Click Edit in the top right corner.
  3. Modify azure-pipelines.yml file using sample code below:
- master

pool:
  vmImage: ubuntu-latest

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'
  continueOnError: true
  env:
    BROWSERSTACK_USERNAME: '$(BROWSERSTACK_USERNAME)'
    BROWSERSTACK_ACCESS_KEY: '$(BROWSERSTACK_ACCESS_KEY)'
  displayName: 'Building Maven'

- bash: |
    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="<Project Name>" -F "file_path=@target/surefire-reports/junitreports/TEST-com.browserstack.BStackDemoTest.xml" -F test_run_name='Test Run - $(Build.BuildNumber)' -F user_email='$(EMAIL)'
  env:
    TEST_MANAGEMENT_API_TOKEN: '$(TEST_MANAGEMENT_API_TOKEN)'
    EMAIL: '$(EMAIL)'
  displayName: 'Publish to Test management'
Note: For this code to work, it is required to define the secret variables BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY, EMAIL and TEST_MANAGEMENT_API_TOKEN in Azure with your BrowserStack’s Automate username and BrowserStack’s Automate Access Key, BrowserStack’s Test Management Token and registered email address as explained below.

Step 2: Click Run

Step 3: Wait for build to complete successfully

This build will generate test reports which shall be of following formats

<?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 -->
[
  {
    "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": []
  }
]

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