8.32.4 • Published 12 days ago

@wdio/reporter v8.32.4

Weekly downloads
298,484
License
MIT
Repository
github
Last release
12 days ago

WebdriverIO Reporter

A WebdriverIO utility to help reporting all events

The @wdio/reporter package can be used to create own custom reporter and publish them to NPM. They have to follow a specific convention as described below in order to work properly. First you need to add @wdio/reporter as dependency of your custom reporter:

npm install @wdio/reporter

or

yarn add @wdio/reporter

Then you need to extend your reporter with the main @wdio/reporter class:

import Reporter from '@wdio/reporter'

export default MyCustomeReporter extends Reporter {
    constructor () {
        super()
        // your custom logic if necessary
        // ...
    }

    onRunnerStart () {
        // ...
    }

    onSuiteStart (suite) {
        // ...
    }

    // ...
}

The Reporter parent class calls your event functions if provided when an event was triggered and provides information on that event in a consistent format. You can always register your own listener to receive the raw data that was provided by the framework, e.g. instead of using the onSuiteStart method you can do:

this.on('suite:start', (raw) => {
    // ...
})

in your constructor function.

Configuration

User can pass in custom configurations for each reporter. Per default WebdriverIO populates the logDir and logLevel option to the reporter, they can get overwritten too. For example, if the user has provided the following reporter options:

// wdio.conf.js
exports.config = {
    // ...
    reporters: ['dot', ['my-reporter', {
        logDir: '/some/path',
        foo: 'bar'
    }]]
    // ...
}

your options in your reporter class are as follows:

export default class MyReporter extends Reporter {
    constructor () {
        super()
        console.log(this.options)
        /**
         * outputs:
         * {
         *   logDir: '/some/path',
         *   logLevel: 'trace',
         *   foo: 'bar'
         * }
         */
    }
}

You can access all options via this.options. You can push logs to stdout or a log file depending of whether the stdout option is true or false. Please use the internal method write that is provided by the Reporter parent class in order to push out logs, e.g.

class MyReporter extends Reporter {
    constructor (options) {
        /**
         * make dot reporter to write to output stream by default
         */
        options = Object.assign(options, { stdout: true })
        super(options)
    }

    // ...
    onTestPass (test) {
        this.write(`test "${test.title}" passed`)
    }
    // ...
}

This will result the following output:

"MyReporter" Reporter:
test "some test" passed
test "some other test" passed

"spec" Reporter:
...

If stdout is set to false WebdriverIO will automatically write to a filestream at a location where other logs are stored as well.

Synchronization

If your reporter needs to do some async computation after the test (e.g. upload logs to a server) you can overwrite the isSynchronised getter method to manage this. By default this property always returns true as most of the reporters don't require to do any async work. However in case you need to handle this overwrite the getter method with an custom implementation (e.g. wdio-sumologic-reporter).

class MyReporter extends Reporter {
    constructor (options) {
        // ...
    }

    get isSynchronised (test) {
        return this.unsyncedMessages.length === 0
    }

    // ...
}

The wdio testrunner will wait to kill the runner process until every reporter has the isSynchronised property set to true.

Events

During a test run in WebdriverIO several events are thrown and can be captured by your event functions. The following events are propagated:

Test Events

These events are containing data about the test regardless of the framework it is running in.

onSuiteStart
SuiteStats {
  type: 'suite',
  start: '2018-02-09T13:30:40.177Z',
  duration: 0,
  uid: 'root suite2',
  cid: '0-0',
  title: 'root suite',
  fullTitle: 'root suite',
  tests: [],
  hooks: [],
  suites: [] } }
onSuiteEnd
SuiteStats {
  type: 'suite',
  start: '2018-02-09T13:30:40.177Z',
  duration: 1432,
  uid: 'root suite2',
  cid: '0-0',
  title: 'root suite',
  fullTitle: 'root suite',
  tests: [ [TestStats] ],
  hooks: [ [HookStats], [HookStats] ],
  suites: [ [Object] ],
  end: '2018-02-09T13:30:41.609Z' } }
onHookStart
HookStats {
  type: 'hook',
  start: '2018-02-09T13:30:40.181Z',
  duration: 0,
  uid: '"before each" hook4',
  cid: '0-0',
  title: '"before each" hook',
  parent: 'root suite',
  parentUid: 'root suite2' } }
onHookEnd
HookStats {
  type: 'hook',
  start: '2018-02-09T13:30:40.181Z',
  duration: 1,
  uid: '"before each" hook4',
  cid: '0-0',
  title: '"before each" hook',
  parent: 'root suite',
  parentUid: 'root suite2',
  end: '2018-02-09T13:30:40.182Z' } }
onTestStart
TestStats {
  type: 'test',
  start: '2018-02-09T13:30:40.180Z',
  duration: 0,
  uid: 'passing test3',
  cid: '0-0',
  title: 'passing test',
  fullTitle: 'passing test',
  state: 'pending' } }
onTestSkip
TestStats {
  type: 'test',
  start: '2018-02-09T14:01:04.573Z',
  duration: 0,
  uid: 'skipped test6',
  cid: '0-0',
  title: 'skipped test',
  fullTitle: 'skipped test',
  state: 'skipped' }
onTestPass
TestStats {
  type: 'test',
  start: '2018-02-09T14:11:28.075Z',
  duration: 1503,
  uid: 'passing test3',
  cid: '0-0',
  title: 'passing test',
  fullTitle: 'passing test',
  state: 'passed',
  end: '2018-02-09T14:11:29.578Z' } }
onTestFail
TestStats {
     type: 'test',
     start: '2018-02-09T14:11:29.581Z',
     duration: 21,
     uid: 'failing test8',
     cid: '0-0',
     title: 'failing test',
     fullTitle: 'failing test',
     state: 'failed',
     end: '2018-02-09T14:11:29.602Z',
     error:
      { message: 'some error',
        stack: `Error: some error\n    at Context.it (/path/to/project/test/b.js:17:19)\n
  at /path/to/project/packages/wdio-sync/src/index.js:490:28\n    at Promise (<anonymous>)\
n    at F (/path/to/project/node_modules/core-js/library/modules/_export.js:35:28)\n    at
Context.executeSync (/path/to/project/packages/wdio-sync/src/index.js:488:12)\n    at /path/to/project/packages/wdio-sync/src/index.js:623:33`,
        type: 'Error' } } }
onTestEnd
TestStats {
  type: 'test',
  start: '2018-02-09T14:11:28.075Z',
  duration: 1503,
  uid: 'passing test3',
  cid: '0-0',
  title: 'passing test',
  fullTitle: 'passing test',
  state: 'passed',
  end: '2018-02-09T14:11:29.578Z' } }

Runner Events

These events contain information on the test runner.

onRunnerStart
RunnerStats {
  type: 'runner',
  start: '2018-02-09T14:30:19.871Z',
  duration: 0,
  cid: '0-0',
  capabilities:
   { acceptInsecureCerts: false,
     browserName: 'firefox',
     browserVersion: '59.0',
     'moz:accessibilityChecks': false,
     'moz:headless': false,
     'moz:processID': 92113,
     'moz:profile': '/var/folders/ns/8mj2mh0x27b_gsdddy1knnsm0000gn/T/rust_mozprofile.jlpfs632Becb',
     'moz:webdriverClick': true,
     pageLoadStrategy: 'normal',
     platformName: 'darwin',
     platformVersion: '17.3.0',
     rotatable: false,
     timeouts: { implicit: 0, pageLoad: 300000, script: 30000 } },
  sanitizedCapabilities: 'firefox.59_0.darwin',
  config: [Object],
  specs: [ '/path/to/project/test/my.test.js' ] }
onRunnerEnd
RunnerStats {
  type: 'runner',
  start: '2018-02-09T14:30:19.871Z',
  duration: 1546,
  uid: undefined,
  cid: '0-0',
  capabilities: [Object],
  sanitizedCapabilities: 'firefox.59_0.darwin',
  config: [Object],
  specs: [ '/path/to/project/test/my.test.js' ],
  failures: 1,
  end: '2018-02-09T14:30:21.417Z' } }

Client Events

Client events are triggered when certain interactions with the automation driver are happening.

onBeforeCommand
{ method: 'GET',
  endpoint: '/session/:sessionId/element',
  body: { using: 'css selector', value: 'img' }
  cid: '0-0',
  sessionId: '4d1707ae-820f-1645-8485-5a820b2a40da',
  capabilities: [Object] }
onAfterCommand
{ method: 'GET',
  endpoint: '/session/:sessionId/element/fbf57b79-6521-7d49-b3b7-df91cf2c347a/rect',
  body: {},
  result: { value: { x: 75, y: 11, width: 160, height: 160 } },
  cid: '0-0',
  sessionId: '4d1707ae-820f-1645-8485-5a820b2a40da',
  capabilities: [Object] }
@patricksevat/wdio-json-reporter-retriesciq-automation-xray-reporterwdio-cool-reporter@infinitebrahmanuniverse/nolb-_wdjavascript-agent-webdriverwdio-zebr-reporter@everything-registry/sub-chunk-1004my-second-love@ionic/wdio-reporter@ionic/wdio-service@valentin.condurache/wdio-junit-reporter@ukhomeoffice/asl-functional-testing@zebrunner/javascript-agent-webdriverio@wdio/allure-reporter@wdio/concise-reporter@wdio/browserstack-service@wdio/dot-reporter@wdio/json-reporter@wdio/junit-reporter@wdio/sumologic-reporter@wdio/testrail-reporter@wdio/smoke-test-reporter@wdio/spec-reporter@wyh.michael/wdio-json-reporter@zalastax/nolb-_wd@andrius-vet/wdio-timeline-reporter@alexbradford3/wdio-timeline-reporter@b1zzu/wdio-cucumberjs-json-reportertestrail-wdio-custom-reportertestrail-wdio-reportertestrail-wdio-reporter-2022wdio-mocha-emailable-reporterwdio-mochajson-reporterwdio-mochawesome-reporterwdio-ms-teams-servicewdio-light-reporterwdio-reporter-htmlwdio-reportportal-reporterwdio-reportportal-reporter-extendedwdio-selenoid-video-reporterwdio-testrail-v7-reporterwdio-testrecorder-reporterwdio-tesults-reporterwdio-timeline-prometheus-reporterwdio-timeline-reporterwdio-json-reporterwdio-json-retries-reporterwdio-json-steps-reporterwdio-tapp-reporterwdio-teamcity-reporterwdio-test-reporterwdio-testrail-tags-reporterwdio-cucumberjs-json-reporterwdio-cucumberjs-json-reporter-fixedwdio-cucumberjs-json-reporter-with-typescriptwdio-cucumberjs-json-reporter-with-typescript-reporterwdio-cucumberjsfixed-json-reporterwdio-docx-evidwdio-graspit-reporterwdio-handshake-reporterwdio-fefanf-html-reporterwdio-fefanf-html-visreg-reporterwdio-cucumber-console-reporterwdio-cucumber-html-reporterwdio-azure-devops-test-reporterwdio-basic-xray-json-reporterwdio-bitb-reporterwdio-browser-utilitieswdio-browserstack-spec-reporterwdio-browserutilswdio-5-testrail-reporterwdio-agent-reporterwdio-video-reporterwdio-visual-regression-reporterwdio-wdiov5testrail-modified-reporterwdio-ciq-automation-xray-reporterwdio-ciq-automation-xray-reporter-barakwdio-coverage-reporterwdio-zafira-listener-servicewdio-zafira-servicewdio-zephyr-reporterwdio-wdiov5testrail-reporterwdio-wdiov5testrail-reporter-asychronoussharpeyespec-reporter-ngterra-toolkitreporter-with-typescript@cerner/terra-functional-testing@criszalo1997/wdio-azure-devops-service@gmangiapelo/wdio-azure-devops-servicecourgettecustom-webdriver-v5-json-reportercraig-wdio-rp-reportercucumberjs-json-reporter-with-typescript-reporter@espekkaya/wdio-cucumber-reporter@espekkaya/wdio-jasmine-reporter@espekkaya/wdio-mocha-reporter@ericmconnelly/wdio-slack-reporter@eznxxy/wdio-timeline-reportere5-allure-reporter
9.0.0-alpha.9

12 days ago

9.0.0-alpha.0

17 days ago

8.32.4

25 days ago

8.32.2

1 month ago

8.31.1

2 months ago

8.31.0

2 months ago

8.30.0

2 months ago

8.29.1

2 months ago

8.29.0

2 months ago

8.28.6

2 months ago

8.28.0

2 months ago

8.27.2

3 months ago

8.27.0

3 months ago

8.26.3

3 months ago

8.26.2

3 months ago

8.24.8

4 months ago

8.24.9

4 months ago

8.24.12

4 months ago

8.19.0

5 months ago

8.12.2

9 months ago

8.12.1

9 months ago

8.23.0

5 months ago

8.23.1

4 months ago

8.24.0

4 months ago

8.15.10

7 months ago

8.24.2

4 months ago

8.14.0

8 months ago

7.33.0

6 months ago

8.16.17

6 months ago

8.16.12

6 months ago

8.15.0

8 months ago

8.16.22

6 months ago

8.15.7

7 months ago

8.15.6

7 months ago

8.16.3

7 months ago

8.16.7

7 months ago

8.17.0

6 months ago

8.20.0

5 months ago

8.21.0

5 months 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.18.0

2 years ago

8.11.0

10 months ago

7.25.1

1 year ago

7.25.0

2 years ago

8.6.6

1 year ago

7.21.0

2 years ago

8.0.0-alpha.240

2 years ago

8.6.8

1 year ago

8.0.0-alpha.411

1 year ago

7.29.1

1 year ago

7.25.4

1 year ago

8.0.0-alpha.412

1 year ago

8.1.0

1 year ago

8.1.2

1 year ago

8.0.0-alpha.537

1 year ago

8.0.0-alpha.620

1 year ago

8.0.10

1 year ago

7.17.3

2 years ago

8.0.11

1 year ago

8.0.14

1 year ago

8.0.0-alpha.589

1 year ago

8.0.13

1 year ago

8.0.0-alpha.621

1 year ago

8.0.0-alpha.507

1 year ago

8.0.0-alpha.505

1 year ago

8.0.0-alpha.504

1 year ago

8.0.0-alpha.629

1 year ago

8.0.0-alpha.508

1 year ago

7.20.0

2 years ago

8.7.0

12 months ago

7.24.1

2 years ago

7.28.0

1 year ago

7.20.7

2 years ago

7.24.0

2 years ago

7.20.3

2 years ago

8.0.0-alpha.631

1 year ago

8.0.0-alpha.598

1 year ago

8.0.0-alpha.630

1 year ago

8.0.0-alpha.239

2 years ago

8.0.0-alpha.512

1 year ago

8.0.0-alpha.518

1 year ago

8.0.0-alpha.516

1 year ago

7.31.0

12 months ago

7.31.1

12 months ago

8.0.0-alpha.593

1 year ago

8.0.0-alpha.565

1 year ago

8.0.0-alpha.563

1 year ago

8.0.0-alpha.327

2 years ago

8.0.0-alpha.600

1 year ago

8.0.0-alpha.329

2 years ago

8.0.0-alpha.328

2 years ago

8.0.0-alpha.607

1 year ago

8.8.0

12 months ago

8.0.8

1 year ago

8.4.0

1 year ago

8.0.7

1 year ago

8.0.6

1 year ago

8.8.4

12 months ago

8.8.7

11 months ago

8.8.6

11 months 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

1 year ago

8.3.0

1 year ago

8.0.0-alpha.219

2 years ago

8.0.0-alpha.619

1 year ago

8.0.0-alpha.330

2 years ago

7.30.2

1 year ago

7.19.5

2 years ago

8.0.0-alpha.547

1 year ago

7.19.1

2 years ago

8.10.0

11 months ago

7.19.0

2 years ago

8.10.2

11 months ago

8.10.1

11 months ago

8.10.4

10 months ago

8.10.6

10 months ago

7.19.7

2 years ago

7.26.0

1 year ago

8.0.0-alpha.558

1 year ago

8.0.0

1 year ago

7.16.13

2 years ago

7.16.14

2 years ago

7.16.11

2 years ago

7.16.1

2 years ago

7.16.3

2 years ago

7.16.0

2 years ago

7.14.1

2 years ago

7.13.2

3 years ago

7.13.0

3 years ago

7.12.5

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

3 years ago

7.7.5

3 years ago

7.7.1-next

3 years ago

7.7.0

3 years ago

7.7.3

3 years ago

7.6.0

3 years ago

7.5.3

3 years ago

7.5.2

3 years ago

7.5.7

3 years ago

7.5.6

3 years ago

7.4.2

3 years ago

7.4.1

3 years ago

7.4.0

3 years ago

7.3.1

3 years ago

7.3.0

3 years ago

7.2.1

3 years ago

7.2.0

3 years ago

7.1.1

3 years ago

7.0.7

3 years ago

7.0.4

3 years ago

7.0.3

3 years ago

7.0.2

3 years ago

7.0.0

3 years ago

7.0.0-beta.4

3 years ago

7.0.0-beta.1

3 years ago

7.0.0-beta.0

3 years ago

6.11.0

3 years ago

6.10.6

3 years ago

6.8.1

3 years ago

6.7.0

3 years ago

6.6.6

3 years ago

6.6.0

3 years ago

6.4.7

4 years ago

6.3.6

4 years ago

6.3.0

4 years ago

6.1.23

4 years ago

6.1.14

4 years ago

6.1.9

4 years ago

6.1.5

4 years ago

6.0.14

4 years ago

6.0.12

4 years ago

6.0.11

4 years ago

6.0.8

4 years ago

6.0.7

4 years ago

6.0.6

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.22.4

4 years ago

5.18.6

4 years ago

6.0.0-alpha.1

4 years ago

6.0.0-alpha.0

4 years ago

5.15.2

4 years ago

5.14.5

4 years ago

5.14.4

4 years ago

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

5 years ago

5.7.8

5 years ago

5.7.2

5 years ago

5.7.0

5 years ago

5.6.4

5 years ago

5.6.0

5 years ago

5.5.0

5 years ago

5.4.15

5 years ago

5.4.3

5 years ago

5.2.3

5 years ago

5.2.2

5 years ago

5.1.0

5 years ago

5.0.3

5 years ago

5.0.0

5 years ago

5.0.0-beta.16

5 years ago

5.0.0-beta.15

5 years ago

5.0.0-beta.14

5 years ago

5.0.0-beta.13

5 years ago

5.0.0-beta.12

5 years ago

5.0.0-beta.10

5 years ago

5.0.0-beta.9

5 years ago

5.0.0-beta.8

5 years ago

5.0.0-beta.7

5 years ago

5.0.0-beta.6

5 years ago

5.0.0-beta.5

5 years ago