Custom Reporter
You can write your own custom reporter for the WDIO test runner that is tailored to your needs. And it’s easy!
All you need to do is to create a node module that inherits from the @wdio/reporter
package, so it can receive messages from the test.
The basic setup should look like:
import WDIOReporter from '@wdio/reporter'
export default class CustomReporter extends WDIOReporter {
constructor(options) {
/*
* make reporter to write to the output stream by default
*/
options = Object.assign(options, { stdout: true })
super(options)
}
onTestPass(test) {
this.write(`Congratulations! Your test "${test.title}" passed 👏`)
}
}
To use this reporter, all you need to do is assign it to the reporter
property in your configuration.
Your wdio.conf.js
file should look like this:
import CustomReporter from './reporter/my.custom.reporter'
export const config = {
// ...
reporters: [
/**
* use imported reporter class
*/
[CustomReporter, {
someOption: 'foobar'
}]
/**
* use absolute path to reporter
*/
['/path/to/reporter.js', {
someOption: 'foobar'
}]
],
// ...
}
You can also publish the reporter to NPM so everyone can use it. Name the package like other reporters wdio-<reportername>-reporter
, and tag it with keywords like wdio
or wdio-reporter
.
Event Handler
You can register an event handler for several events which are triggered during testing. All of the following handlers will receive payloads with useful information about the current state and progress.
The structure of these payload objects depend on the event, and are unified across the frameworks (Mocha, Jasmine, and Cucumber). Once you implement a custom reporter, it should work for all frameworks.
The following list contains all possible methods you can add to your reporter class:
import WDIOReporter from '@wdio/reporter'
export default class CustomReporter extends WDIOReporter {
onRunnerStart() {}
onBeforeCommand() {}
onAfterCommand() {}
onSuiteStart() {}
onHookStart() {}
onHookEnd() {}
onTestStart() {}
onTestPass() {}
onTestFail() {}
onTestSkip() {}
onTestEnd() {}
onSuiteEnd() {}
onRunnerEnd() {}
}