Skip to main content

JUnit-XML based WebdriverIO report

Using the terminal, you can create JUnit-XML based reports from WebdriverIO and upload them to Test Management.

Executing a Test Case with WebdriverIO

You can initiate a WebdriverIO project with this git repository. Use this sample code to execute a Test Case.

describe('First Steps with WebdriverIO', () => {

    it('Load BStack Demo Website', () => {
        browser.url('https://www.bstackdemo.com')
        browser.pause(1000)
        expect(browser).toHaveUrl('https://www.bstackdemo.com')
    })

    it('Load WebdriverIO Website', () => {
        browser.url('https://webdriver.io')
        browser.pause(1000)
    })

});

describe('Second Steps with WebdriverIO', () => {

    it('Second load BStack Demo Website', () => {
        browser.url('https://www.bstackdemo.com')
        browser.pause(1000)
        expect(browser).toHaveTitle('BrowserStack Demo')
    })

});

Create JUnit-XML test report with WebdriverIO

Install the official @wdio/junit-reporter package.

npm install @wdio/junit-reporter --save-dev

Enable the junit-reporter in WebDriverIO configuration file.

"// wdio.conf.js
module.exports = {
    // ...
    reporters: [
        'dot',
        ['junit', {
            outputDir: './results',
            outputFileFormat: function() {
                return `test-results.xml`
            }
        }]
    ],
    // ...
};"

Sample JUnit-XML report generated from WebdriverIO in the output folder.

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="First Steps with WebdriverIO" timestamp="2023-06-19T19:59:22" time="0.02" tests="2" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="First Steps with WebdriverIO"/>
      <property name="capabilities" value="chrome.114_0_5735_106.macosx"/>
      <property name="file" value="file://./test/specs/example.js"/>
    </properties>
    <testcase classname="chrome.114_0_5735_106.macosx.First_Steps_with_WebdriverIO" name="Load BStack Demo Website" time="0.005">
      <system-out><![CDATA[
COMMAND: GET /session/adb95d79422dfe4f91d3f07ec1a5a7dd/url - {}
COMMAND: POST /session/adb95d79422dfe4f91d3f07ec1a5a7dd/url - {"url":"https://www.bstackdemo.com/"}
]]></system-out>
    </testcase>
    <testcase classname="chrome.114_0_5735_106.macosx.First_Steps_with_WebdriverIO" name="Load WebdriverIO Website" time="0.001">
      <system-out><![CDATA[
COMMAND: POST /session/adb95d79422dfe4f91d3f07ec1a5a7dd/url - {"url":"https://webdriver.io/"}
RESULT: {}
]]></system-out>
    </testcase>
  </testsuite>
  <testsuite name="Second Steps with WebdriverIO" timestamp="2023-06-19T19:59:22" time="0.01" tests="1" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="Second Steps with WebdriverIO"/>
      <property name="capabilities" value="chrome.114_0_5735_106.macosx"/>
      <property name="file" value="file://./test/specs/example.js"/>
    </properties>
    <testcase classname="chrome.114_0_5735_106.macosx.Second_Steps_with_WebdriverIO" name="Second load BStack Demo Website" time="0.003">
      <system-out><![CDATA[
COMMAND: GET /session/adb95d79422dfe4f91d3f07ec1a5a7dd/title - {}
COMMAND: POST /session/adb95d79422dfe4f91d3f07ec1a5a7dd/url - {"url":"https://www.bstackdemo.com/"}
COMMAND: DELETE /session/adb95d79422dfe4f91d3f07ec1a5a7dd - {}
COMMAND: GET /session/adb95d79422dfe4f91d3f07ec1a5a7dd/url - {}
RESULT: {"url":"https://www.bstackdemo.com/"}
RESULT: {"url":"https://webdriver.io/"}
RESULT: {}
RESULT: {"url":"https://www.bstackdemo.com/"}
RESULT: {}
]]></system-out>
    </testcase>
  </testsuite>
</testsuites>

Steps to upload the JUnit-XML test report

Open the project directory in the Terminal and load the variables.

export TEST_MANAGEMENT_API_TOKEN="*************28a42"
export TEST_MANAGEMENT_PROJECT_NAME="<Project Name>"
export JUNIT_XML_FILE_PATH="<Report Path>"
export TEST_RUN_NAME="<Test Run Name"
Note: You can get your TEST_MANAGEMENT_API_TOKEN from the Active API Key section in the Settings of BrowserStack Test Management.

Upload the test report using curl command.

curl -k -X POST https://test-management.browserstack.com/api/v1/import/results/xml/junit \
-u $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"
Note: Report upload will take a few seconds to about a minute depending on the size of your test-suite. Do not interrupt the cURL command until you get the response back.

You can also upload JUnit-XML test report with WebdriverIO using CI/CD.

Access the test run report from the console generated URL

After your report is successfully uploaded, you see a message similar to the following in your terminal. This message also generates a URL with "url" parameter that you can use to access your automated test run.

{"message":"File uploaded successfully.","url":"https://test-management.browserstack.com/projects/<project id>/test-runs/<test run id>","success":true}

View test run report in Test Management

  1. Log in to the BrowserStack Test Management dashboard.
  2. Select the relevant project that has the test report uploaded.
  3. Click Test Runs.
  4. Open the Test Run generated from automation test exectution.
  5. You will find all the test cases with their respective results here.

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