Skip to main content

Integrate Azure DevOps with BrowserStack Test Management

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

Prerequisites

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

Modify the azure-pipelines.yml file

  1. Open your Azure pipeline and click Edit in the top right corner.
  2. Modify azure-pipelines.yml file with the following sample code.
- 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 DevOps with your BrowserStack’s username and Access Key, Test Management API Token, and registered email ID.
  • You can get your TEST_MANAGEMENT_API_TOKEN from the Active API Key section on the Test Management Settings page.

Run and generate test reports

Click Run Pipeline in your Azure DevOps pipeline. Wait for build to complete successfully and generate the test reports. Following are the 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