9.4.4 • Published 6 days ago

@wdio/junit-reporter v9.4.4

Weekly downloads
94,442
License
MIT
Repository
github
Last release
6 days ago

WebdriverIO XML Reporter

A WebdriverIO reporter that creates Jenkins compatible XML based JUnit reports

Installation

The easiest way is to keep @wdio/junit-reporter as a devDependency in your package.json, via:

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

Instructions on how to install WebdriverIO can be found here.

Output

This reporter will output a report for each runner, so in turn you will receive an xml report for each spec file. Below are examples of XML output given different scenarios in the spec file.

Single describe block

describe('a test suite', () => {
    it('a test case', function () {
      // do something
      // assert something
    });
});

becomes

<testsuites>
    <testsuite name="a test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
        <properties>
          <property name="specId" value="0"/>
          <property name="suiteName" value="a test suite"/>
          <property name="capabilities" value="chrome"/>
          <property name="file" value=".\test\specs\asuite.spec.js"/>
        </properties>
        <testcase classname="chrome.a_test_case" name="a_test_suite_a_test_case" time="11.706"/>
    </testsuite>
</testsuites>

Nested describe block

describe('a test suite', () => {
    describe('a nested test suite', function() {
        it('a test case', function () {
          // do something
          // assert something
        });
    });
});

becomes

<testsuites>
    <testsuite name="a test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="a test suite"/>
      <property name="capabilities" value="chrome"/>
      <property name="file" value=".\test\specs\asuite.spec.js"/>
    </properties>
  </testsuite>
  <testsuite name="a nested test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="a nested test suite"/>
      <property name="capabilities" value="chrome"/>
      <property name="file" value=".\test\specs\asuite.spec.js"/>
    </properties>
    <testcase classname="chrome.a_test_case" name="a nested test suite a test case" time="11.706"/>
  </testsuite>
</testsuites>

Multiple describe block

describe('a test suite', () => {
    it('a test case', function () {
      // do something
      // assert something
    });
});
describe('a second test suite', () => {
    it('a second test case', function () {
      // do something
      // assert something
    });
});

becomes

<testsuites>
    <testsuite name="a test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="a test suite"/>
      <property name="capabilities" value="chrome"/>
      <property name="file" value=".\test\specs\asuite.spec.js"/>
      <testcase classname="chrome.a_test_case" name="a nested test suite a test case" time="11.706"/>
    </properties>
  </testsuite>
  <testsuite name="a second test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="a second test suite"/>
      <property name="capabilities" value="chrome"/>
      <property name="file" value=".\test\specs\asuite.spec.js"/>
    </properties>
    <testcase classname="chrome.a_second_test_case" name="a_second_test_suite_a_second_test_case" time="11.706"/>
  </testsuite>
</testsuites>

Failures and Errors

All test case failures are mapped as JUnit test case errors. A failed test case due to assertion failure or error will look like:

<testcase classname="chrome.a_test_case" name="a_test_suite_a_test_case" time="0.372">
  <failure message="Error: some error"/>
    <system-err>
        <![CDATA[
Error: some assertion failure
    at UserContext.<anonymous> (C:\repo\webdriver-example\test\specs/a_test_suite.spec.js:22:17)
]]>
  </system-err>
</testcase>

Configuration

Following code shows the default wdio test runner configuration. Just add 'junit' as reporter to the array. To get some output during the test you can run the WDIO Dot Reporter and the WDIO JUnit Reporter at the same time:

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

The following options are supported:

outputDir

Define a directory where your xml files should get stored.

Type: String Required

outputFileFormat

Define the xml files created after the test execution.

Type: Object Default: function (opts) { return `wdio-${this.cid}-${name}-reporter.log` }

outputFileFormat: function (options) {
    return 'mycustomfilename.xml';
}

Note: options.capabilities is your capabilities object for that runner, so specifying ${options.capabilities} in your string will return Object object. You must specify which properties of capabilities you want in your filename.

suiteNameFormat

Gives the ability to provide custom regex for formatting test suite name (e.g. in output xml ).

Type: Regex, Default: /[^a-zA-Z0-9@]+/

// wdio.conf.js
module.exports = {
    // ...
    reporters: [
        'dot',
        ['junit', {
            outputDir: './',
            suiteNameFormat: /[^a-zA-Z0-9@]+/
            outputFileFormat: function(options) { // optional
                return `results-${options.cid}.${options.capabilities}.xml`
            }
        }]
    ],
    // ...
};

addFileAttribute

Adds a file attribute to each testcase. This config is primarily for CircleCI. This setting provides richer details but may break on other CI platforms.

Type: Boolean, Default: false

packageName

You can break out packages by an additional level by setting 'packageName'. For example, if you wanted to iterate over a test suite with different environment variable set:

Type: String Example:

// wdio.conf.js
module.exports = {
    // ...
    reporters: [
        'dot',
        ['junit', {
            outputDir: './',
            packageName: process.env.USER_ROLE // chrome.41 - administrator
        }]
    ]
    // ...
};

errorOptions

Allows to set various combinations of error notifications inside xml. Given a Jasmine test like expect(true).toBe(false, 'my custom message') you will get this test error:

{
    matcherName: 'toBe',
    message: 'Expected true to be false, \'my custom message\'.',
    stack: 'Error: Expected true to be false, \'my custom message\'.\n    at UserContext.it (/home/mcelotti/Workspace/WebstormProjects/forcebeatwio/test/marco/prova1.spec.js:3:22)',
    passed: false,
    expected: [ false, 'my custom message' ],
    actual: true
}

Therefore you can choose which key will be used where, see the example below.

Type: Object, Default: errorOptions: { error: "message" } Example:

// wdio.conf.js
module.exports = {
    // ...
    reporters: [
        'dot',
        ['junit', {
            outputDir: './',
            errorOptions: {
                error: 'message',
                failure: 'message',
                stacktrace: 'stack'
            }
        }]
    ],
    // ...
};

Jenkins Setup

Last but not least you need to tell your CI job (e.g. Jenkins) where it can find the xml file. To do that, add a post-build action to your job that gets executed after the test has run and point Jenkins (or your desired CI system) to your XML test results:

Point Jenkins to XML files

If there is no such post-build step in your CI system there is probably a plugin for that somewhere on the internet.


For more information on WebdriverIO see the homepage.

9.4.4

6 days ago

9.4.3

7 days ago

7.40.0

7 days ago

8.41.0

7 days ago

9.4.2

13 days ago

9.2.14

1 month ago

9.2.2

2 months ago

9.1.3

3 months ago

9.1.2

3 months ago

9.1.1

3 months ago

8.40.6

3 months ago

9.1.0

3 months ago

9.0.8

4 months ago

9.0.4

4 months ago

9.0.0

4 months ago

8.40.3

4 months ago

9.0.0-alpha.426

5 months ago

8.40.0

5 months ago

9.0.0-alpha.350

6 months ago

9.0.0-alpha.351

6 months ago

8.39.0

6 months ago

9.0.0-alpha.321

6 months ago

9.0.0-alpha.367

6 months ago

9.0.0-alpha.369

6 months ago

8.38.2

7 months ago

8.37.0

7 months ago

8.38.0

7 months ago

9.0.0-alpha.113

8 months ago

9.0.0-alpha.114

8 months ago

9.0.0-alpha.115

8 months ago

8.36.1

8 months ago

8.36.0

9 months ago

9.0.0-alpha.78

9 months ago

9.0.0-alpha.59

9 months ago

9.0.0-alpha.64

9 months ago

9.0.0-alpha.9

9 months ago

9.0.0-alpha.0

10 months ago

8.32.4

10 months ago

8.32.2

10 months ago

7.35.0

11 months ago

8.31.1

11 months ago

8.31.0

11 months ago

8.30.0

11 months ago

8.29.1

11 months ago

8.29.0

11 months ago

8.28.6

11 months ago

8.28.0

11 months ago

8.27.2

12 months ago

8.27.0

1 year ago

8.26.3

1 year ago

8.26.2

1 year ago

8.24.8

1 year ago

8.24.9

1 year ago

8.24.12

1 year ago

8.11.3

1 year ago

8.19.0

1 year ago

8.12.2

1 year ago

8.12.1

1 year ago

8.23.0

1 year ago

8.23.1

1 year ago

8.24.0

1 year ago

8.15.10

1 year ago

8.24.2

1 year ago

8.14.0

1 year ago

7.33.0

1 year ago

8.16.17

1 year ago

8.16.12

1 year ago

8.15.0

1 year ago

8.16.22

1 year ago

8.15.7

1 year ago

8.15.6

1 year ago

8.15.9

1 year ago

8.16.1

1 year ago

8.16.3

1 year ago

8.16.7

1 year ago

8.17.0

1 year ago

8.20.0

1 year ago

8.21.0

1 year ago

7.18.0

3 years ago

8.11.0

2 years ago

7.21.0

2 years ago

8.0.0-alpha.411

2 years ago

7.29.1

2 years ago

8.0.0-alpha.412

2 years ago

8.1.0

2 years ago

8.1.2

2 years ago

8.0.0-alpha.537

2 years ago

7.20.8-alpha.219

2 years ago

8.0.0-alpha.620

2 years ago

7.17.3

3 years ago

8.0.0-alpha.621

2 years ago

8.0.0-alpha.507

2 years ago

8.0.0-alpha.505

2 years ago

8.0.0-alpha.504

2 years ago

8.0.0-alpha.629

2 years ago

8.0.0-alpha.508

2 years ago

7.20.0

3 years ago

7.28.0

2 years ago

7.20.7

2 years ago

7.20.3

3 years ago

8.0.0-alpha.631

2 years ago

8.0.0-alpha.630

2 years ago

8.0.0-alpha.512

2 years ago

8.0.0-alpha.518

2 years ago

8.0.0-alpha.516

2 years ago

8.2.0

2 years ago

7.31.0

2 years ago

7.31.1

2 years ago

8.0.0-alpha.565

2 years ago

8.0.0-alpha.563

2 years ago

8.0.0-alpha.327

2 years ago

8.0.0-alpha.329

2 years ago

8.0.0-alpha.328

2 years ago

8.4.0

2 years ago

7.23.0

2 years ago

8.0.0-alpha.213

2 years ago

8.0.0-alpha.331

2 years ago

8.0.0-alpha.577

2 years ago

8.3.0

2 years ago

8.0.0-alpha.219

2 years ago

8.0.0-alpha.330

2 years ago

7.19.5

3 years ago

8.0.0-alpha.547

2 years ago

7.19.1

3 years ago

7.19.0

3 years ago

7.19.7

3 years ago

8.0.0-alpha.558

2 years ago

8.0.0-alpha.365

2 years ago

8.0.0-alpha.243

2 years ago

8.0.0-alpha.249

2 years ago

7.20.8-alpha.504

2 years ago

7.25.1

2 years ago

7.25.0

2 years ago

8.6.6

2 years ago

8.0.0-alpha.240

2 years ago

8.6.8

2 years ago

7.25.4

2 years ago

8.0.10

2 years ago

8.0.11

2 years ago

8.0.14

2 years ago

8.0.0-alpha.589

2 years ago

8.0.13

2 years ago

8.7.0

2 years ago

7.24.1

2 years ago

7.24.0

2 years ago

8.0.0-alpha.598

2 years ago

8.0.0-alpha.239

2 years ago

8.0.0-alpha.593

2 years ago

8.0.0-alpha.600

2 years ago

8.0.0-alpha.607

2 years ago

8.8.0

2 years ago

8.0.8

2 years ago

8.0.7

2 years ago

8.0.6

2 years ago

8.8.4

2 years ago

8.8.7

2 years ago

8.8.6

2 years ago

8.0.0-alpha.619

2 years ago

7.30.2

2 years ago

8.10.0

2 years ago

8.10.2

2 years ago

8.10.1

2 years ago

8.10.4

2 years ago

8.10.6

2 years ago

7.26.0

2 years ago

8.0.0

2 years ago

7.16.15

3 years ago

7.16.13

3 years ago

7.16.14

3 years ago

7.16.11

3 years ago

7.16.12

3 years ago

7.16.1

3 years ago

7.16.6

3 years ago

7.16.4

3 years ago

7.16.3

3 years ago

7.16.0

3 years ago

7.15.0

3 years ago

7.14.1

3 years ago

7.13.2

3 years ago

7.13.0

3 years ago

7.12.5

3 years ago

7.12.1

3 years ago

7.11.1

3 years ago

7.10.1

3 years ago

7.10.0

3 years ago

7.9.0

3 years ago

7.8.0

3 years ago

7.7.8

3 years ago

7.7.7

3 years ago

7.7.5

3 years ago

7.7.0

4 years ago

7.7.3

4 years ago

7.5.3

4 years ago

7.5.2

4 years ago

7.5.7

4 years ago

7.5.6

4 years ago

7.6.0

4 years ago

7.4.2

4 years ago

7.4.1

4 years ago

7.4.0

4 years ago

7.3.1

4 years ago

7.3.0

4 years ago

7.2.1

4 years ago

7.2.0

4 years ago

7.1.2

4 years ago

7.1.1

4 years ago

7.0.7

4 years ago

7.0.4

4 years ago

7.0.3

4 years ago

7.0.2

4 years ago

7.0.1

4 years ago

7.0.0

4 years ago

7.0.0-beta.4

4 years ago

7.0.0-beta.1

4 years ago

7.0.0-beta.0

4 years ago

6.11.0

4 years ago

6.10.6

4 years ago

6.8.1

4 years ago

6.7.0

4 years ago

6.6.6

4 years ago

6.6.0

4 years ago

6.5.1

4 years ago

6.4.7

4 years ago

6.4.0

4 years ago

6.3.6

4 years ago

6.3.4

4 years ago

6.3.3

4 years ago

6.3.2

4 years ago

6.3.0

4 years ago

6.1.25

4 years ago

6.1.23

4 years ago

6.1.14

5 years ago

6.1.9

5 years ago

6.1.5

5 years ago

6.1.2

5 years ago

6.0.14

5 years ago

6.0.12

5 years ago

6.0.11

5 years ago

6.0.8

5 years ago

6.0.7

5 years ago

6.0.6

5 years ago

6.0.4

5 years ago

6.0.1

5 years ago

6.0.0

5 years ago

5.22.4

5 years ago

5.18.6

5 years ago

6.0.0-alpha.1

5 years ago

5.18.3

5 years ago

5.18.0

5 years ago

6.0.0-alpha.0

5 years ago

5.16.11

5 years ago

5.15.5

5 years ago

5.15.2

5 years ago

5.15.1

5 years ago

5.15.0

5 years ago

5.14.5

5 years ago

5.14.4

5 years ago

5.13.2

5 years ago

5.12.3

5 years ago

5.12.2

5 years ago

5.12.1

5 years ago

5.12.0

5 years ago

5.11.7

5 years ago

5.11.0

5 years ago

5.9.3

6 years ago

5.9.1

6 years ago

5.8.0

6 years ago

5.7.16

6 years ago

5.7.11

6 years ago

5.7.8

6 years ago

5.7.2

6 years ago

5.7.0

6 years ago

5.6.4

6 years ago

5.6.0

6 years ago

5.5.0

6 years ago

5.4.18

6 years ago

5.4.15

6 years ago

5.4.9

6 years ago

5.4.8

6 years ago

5.4.3

6 years ago

5.3.1

6 years ago

5.2.3

6 years ago

5.2.2

6 years ago

5.2.1

6 years ago

5.1.0

6 years ago

5.0.3

6 years ago

5.0.0

6 years ago

5.0.0-beta.16

6 years ago

5.0.0-beta.15

6 years ago

5.0.0-beta.14

6 years ago

5.0.0-beta.13

6 years ago

5.0.0-beta.12

6 years ago

5.0.0-beta.11

6 years ago

5.0.0-beta.10

6 years ago

5.0.0-beta.9

6 years ago

5.0.0-beta.8

6 years ago

5.0.0-beta.7

6 years ago

5.0.0-beta.6

6 years ago

5.0.0-beta.5

6 years ago

5.0.0-beta.4

6 years ago