@postman/wdio-junit-reporter

0.0.3 • Public • Published

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.

{
  "devDependencies": {
    "@wdio/junit-reporter": "^6.3.6"
  }
}

You can simple do it by:

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">
  <error 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-z0-9]+/

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.

Package Sidebar

Install

npm i @postman/wdio-junit-reporter

Weekly Downloads

588

Version

0.0.3

License

MIT

Unpacked Size

44 kB

Total Files

12

Last publish

Collaborators

  • arpit.sahu
  • akshat-nema
  • postman-web-platform-functional-account
  • ian.cundiff
  • rebecca.krosnick
  • soriat
  • meetsuraj2
  • nitish-postman
  • shub_postman
  • joshnedelkapostman
  • kevin.corbett
  • surulik
  • carlos.garcia.postman
  • anirudh.ms
  • akira28
  • cecilytoro
  • sumedha.kulkarni
  • suman.das
  • yashishdua
  • rljohnsn
  • salomekbg_postman
  • vtyson
  • indraneel_postman
  • grantkingpostman
  • shivangibajpai12
  • abhilash-postman
  • raghavendra-postman
  • ravi-postman
  • jedliu-postman
  • amaan.khan.postman
  • diwakarshukla_postman
  • imran.munir
  • markgritterpm
  • shruthivee
  • rajaswa
  • aki-kusanagi
  • yokawasa
  • pranjaljn97
  • ankit834
  • saurabh.agarwal
  • itsaamirpostman
  • postmanaut
  • noah.schwartz
  • dkrape
  • saurabh.vartak
  • wheatspaghetti
  • himanshu.ng056
  • honeynair
  • tonyzebastian
  • kasey.seo
  • parthverma
  • neha.kaura
  • josephps
  • parthpverma
  • muskaan06
  • sapnanayak
  • akshay_postman
  • jeroenvdpoll
  • harsuyash
  • ayush.chowdhury
  • plgah
  • sobtiankit
  • aravind-arun
  • smoya
  • mcturco
  • skatikia
  • dhinesh.sridhar
  • aman-pm
  • danek_szy
  • alexgul4enko
  • pamzani
  • fran.mendez
  • jonaslagoni
  • guru.pochineni
  • navneetbhole
  • piyush.daga
  • himanshu.vishwakarma
  • shraddha-arora-postman
  • anshitbansal
  • prathameshh
  • nitishpostman
  • yashja.in
  • varshini59
  • aviralpostman
  • theerthasenan
  • shikharpostman
  • amanpostman
  • greenblade29
  • anuragmewar
  • chris_pm
  • jk-postman
  • tphipps
  • akshay.kulkarni
  • vedkribhu
  • samarth.gulati
  • razvi07
  • cleverom
  • planetabhi
  • tiara.johnson
  • joe.fusco
  • jonathanhaviv
  • mudit.joshi
  • piyush.r
  • anjali2022
  • gkorosc-postman
  • raisinten
  • itsaamir
  • vinayak.parashar
  • rafaeltf
  • apoorv.gupta.postman
  • adrian.santana
  • kylerrenn94
  • jelle.vandevelde
  • atanas.a
  • samithjaganath
  • pranavj2000
  • pwitcher
  • anandh619
  • diegog24
  • atchyut.pulavarthi
  • kevinswiber-postman
  • sanketpath
  • opi-danihelka
  • arvind.khadri
  • cboornazian
  • irena-postman
  • rohan.grover
  • vincentbarth
  • aniketbewal
  • romulo-nascimento
  • ruben.baraut
  • arsh_13
  • tapanchudasama
  • akash.rajpurohit_postman
  • harsh.postman
  • rtlockwood
  • harshit.kochar
  • auddypostman
  • patricksevat
  • akinard-pm
  • ayush.jain
  • laszlogreczi
  • bhoomikaduapostman
  • robertgzr
  • roy-himanshu
  • nidhi_goyal
  • alexander-rubia
  • arjun.golabhanvi
  • anil.jnanoji
  • gbadebo.bello
  • ravi.prasad
  • jatin-postman
  • bharadwajpoduri7
  • liteshpatil17
  • tilak-patel-postman
  • hasnain.rajan
  • elizabeth.fung
  • manavbharambe
  • preetham.m
  • dhuhindhan.ilango
  • nishat.sayyed
  • rubencasas
  • sterling.chin-postman
  • anubhav-vats
  • adityabaradwaj
  • timhall
  • asutosh.sahoo
  • prasant.patel
  • bot_marketing_engineering
  • shreyansh_post
  • vaishnavichalla
  • lorenzo.ambrosi
  • arnaudlauret_postman
  • christina.hastenrathplus1
  • postman-dakshraj.sharma
  • ekansh-01
  • devsharma
  • ayushman9454
  • tonygo
  • postmanian
  • davidtran33
  • rutvik_gs
  • dsanders11
  • akkeshavan
  • rishabh.shukla
  • riyasaini
  • yash-postman
  • karnsharma
  • priyambadamadala
  • gaurav.rakheja
  • suhas_gaikwad
  • umeshp7
  • darshan.sen
  • yatin1997
  • kartikj
  • saswatds
  • sujayvenaik
  • kratigya
  • shubham.ranjan
  • davidespi
  • numaanashraf
  • shamasis
  • godfrzero
  • abhijitkane
  • kunagpal
  • hg07
  • kamalaknn
  • joycifer
  • nikithaachhini
  • shreyas.panduranga
  • pratiksolim
  • sivcansingh
  • bhargavkaranam96
  • raima.zachariah
  • ronak.npm
  • codenirvana
  • tristandenyer
  • sabih.siddiqui
  • shashwat.dixit
  • kriss1897
  • gunjan4542
  • meetdeveloper
  • pawanbana
  • shreyshah
  • vshingala
  • barshan23
  • coditva
  • skrpl
  • jibinmathews7
  • diuda
  • postbot-bitbucket
  • postbot-buildkite
  • dannydainton
  • brandonmcastillo
  • michaelclaus
  • devansh21
  • arshad.ayub
  • sharma.nikhil1997
  • twitharshil
  • smitshah173
  • atishay-postman
  • saket_ranjan
  • dhawan29
  • arlemi.postman
  • akshaytate01
  • pankajk0791
  • mdamankh
  • apoorvajain08
  • james-postman
  • arvind-kalra
  • diptarag
  • dip_postman
  • akshay24
  • chetan.waingankar
  • axelonet
  • balakrishna.avulapati
  • harsha.dixit
  • saialekhya.yerragunta
  • pranav.singhal
  • amrindersandhu
  • deepanshurana
  • mudit1804
  • prashant-raghu
  • waseem.siddiqui
  • hemendra.kumar
  • bswisher
  • himanshu0809
  • avinashchoudhary
  • gouthamaj
  • shubham.joshi
  • ankitsaini
  • dev-pawankumar
  • tim.beauchamp
  • iamnishantgarg
  • amrit_vyas
  • ayush.raj
  • himanshu.s
  • brent.cromarty
  • sandeep.singh
  • abhijeetborole
  • mehul.agrawal
  • sonymathew
  • pravinkk
  • hardik286
  • appurvamurawat
  • poojat
  • phani-postman
  • jviotti
  • chinmayj195
  • harsh_bansal
  • srinivas.kini
  • jony.cheung.postman
  • yash.aggarwal
  • rrc083
  • diya.ninan
  • shruti_paranjape
  • utsav.kapoor1994
  • abhishek_s
  • subhash.yadav
  • pankajkumar05
  • prithvi.tharun
  • ashish.gupta1
  • joshuawise_postman
  • bot.npm.cf.starship
  • divy.khare
  • meenakshi.dhanani