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

  ├── / 
  |   ├── src/
  |   |    ├── my_custom_reporter_lib.js
  |   |    └── my_other_custom_reporter_lib.js
  |   └── test/
  |        ├── test_for_my_custom_reporter_lib.js
  |        └── test_for_my_other_custom_reporter_lib.js
  ├── index.js
  ├── LICENSE.md
  ├── package.json
  └── README.md

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

  1. Install the NPM package for the custom reporter you wish to use:
npm i <nightwatch-custom-reporter>
  1. Use the custom reporter:
nightwatch --reporter=<nightwatch-custom-reporter>