Create a custom reporter
Overview
You can generate your own reports by using the provided the results object. This can be done is at least two main ways:
As a separate file
Step 1. create the file
Define your custom reporter in a separate file (e.g. custom_reporter.js
). Choose either a callback or a Promise to signal that reporting is complete.
custom_reporter.js
module.exports = {
write : function(results, options, done) {
console.log('custom reporting...');
done();
}
};
custom_reporter.js
module.exports = {
write: async function(results, options) {
console.log('custom reporting...');
}
};
Step 2. run the reporter
Run the following command with the correct path to the custom reporter:
nightwatch --reporter=junit --reporter=/path/to/custom_reporter.js
Run the following command to generate multiple reports (the built-in HTML report and the custom_reporter) – since v2.2+:
nightwatch --reporter=/path/to/custom_reporter.js --reporter=html
As an NPM package
A custom reporter can also be published to NPM.
Example
If you're new to publishing NPM packages, read the Creating and publishing unscoped public packages guide first.
The index.js
file needs to implement the same interface as the file-based custom reporter:
index.js
module.exports = {
write: async function(results, options) {
console.log('custom reporting...');
}
};
Usage
- Install the NPM package for the custom reporter you wish to use:
npm i <nightwatch-custom-reporter>
- Use the custom reporter:
nightwatch --reporter=<nightwatch-custom-reporter>