Skip to main content

Jenkins Integration with BrowserStack Test Management

You can integrate Jenkins with BrowserStack Test Management to automate your test runs and generate test reports.

Pre-requisite

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

Integrate Jenkins and Import Test Run reports

Modify or create a Jenkinsfile in your code.

  1. Go to code base.

  2. Open root folder and verify if Jenkinsfile exists. You can also use this sample Jenkinsfile.

  3. Modify the sample code.

.
.
.
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.

Push the codebase to your version controling system like Github or Bitbucket.

Go to your Jenkins Dashboard and select the master branch of your Pipeline. Select master branch on Jenkins pipeline

Select Build with Parameters.

Insert your BrowserStack Test Management parameters.

  • API token of BrowserStack Test Management in TEST_MANAGEMENT_API_TOKEN
  • Name of you Test Management project name in TEST_MANAGEMENT_PROJECT_NAME
  • Name of your test run TEST_RUN_NAME
  • You BrowserStack email ID USER_EMAIL
Note: You can get your TEST_MANAGEMENT_API_TOKEN from the Active API Key section on the Test Management Settings page.

Click Build.

Wait for the build to complete and generate test reports. Here are sample test reports:

<?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