multipleCucumberHTMLreporter

Command Line tool

Command line interface for Multiple Cucumber HTML Reporter.

You can use the command line tool which is newly added to the Multiple Cucumber HTML Reporter. To use it, you need to install it globally on your machine.

Check out the installation step to install the CLI globally.

Check the installation

After you have installed the reporter command line tool globally, run the following command to check if the tool is installed successfully:

mchr --version

Reporter configuration file

The reporter now supports the following configuration files, which you can use to add the common configuration options for the reporter:

  • .multiple-cucumber-html-reporterrc: This file is a JSON format file.
  • .multiple-cucumber-html-reporter.json: In case if you want to explicitly specify the JSON file extension, you can use this file.
  • .multiple-cucumber-html-reporter.js: In case if you want to handle to dynamically set the metadata, you can use this file.
  • .multiple-cucumber-html-reporter.ts: In case you prefer Typescript, then use this file.
  • .multiple-cucumber-html-reporter.yml / .multiple-cucumber-html-reporter.yaml: In case you prefer YAML format, then use this file.

Tip!

The CLI will try to find the config file in the order mentioned above.

Generate configuration file

For your initial setup, you can generate the initial configuration file by running the following command in your terminal:

mchr

This command will do the following:

  • When run for the first time, the CLI will start interactive onboarding process where it will ask you some questions, when you answer these questions, it will then create the JSON format config file named .multiple-cucumber-html-reporter.json.
  • In preceding execution will not trigger onboarding if there is already a configuration file available in the project directory.
  • Next, if will use this configuration file to generate the report, provided that there is Cucucmber JSON reports already generated.
  • The CLI will also print some informative logs while generating the report. You can turn off this info logs by passing the flag --silent or --no-logging with the command.

Tip

If the Cucumber generated JSON file is not generated, then the report would still be generated but it will be empty.

So, it is better to generate the Cucumber JSON report first and then generate the HTML report by using the mchr command.

Tip

The CLI command will default generate the config file in JSON format.

You can later change the format to .yml or .js format as per your preference.

Important

When this command line tool is run in a CI environment, it will automatically Error out if there is no config file present in the folder in which this command is executed.

Basically the interactive onboarding step will be completely skipped on CI environment.

CLI Options

Following are the allowed options in the command line tool:

Prop

Type

Sample configuration file

This is how the sample configuration file for the CLI tool looks like:

{
  "jsonDir": "./.run/reports/json/",
  "reportPath": "./.run/html-report/",
  "openReportInBrowser": true,
  "useCDN": true,
  "metadataFilePath": "./.run/reports/json/metadata.json",
  "customData": {
    "projectName": "Cypress sample project",
    "release": "1.2.0",
    "testCycle": "${GITHUB_RUN_ID:'Cycle 1'}",
    "buildNumber": "${GITHUB_RUN_NUMBER:'Build 1'}",
    "environment": "production",
    "ciPipeline": "GitHub Actions",
  },
  "pageTitle": "Cypress Sample",
  "reportName": "Cypress Sample",
  "displayDuration": true,
  "displayReportTime": true,
}

Note

Refer the Reporter options to know more about the configuration options.

Using environment variable in config file

You can use environment variables in the config file to set the values of the configuration options. If you are having config file in JavaScript / Typescript format, then it is pretty straight forward of using the environment variable as shown below:

import type { Options } from 'multiple-cucumber-html-reporter';

const config: Option = {
  . . .
  testCycle: process.env.GITHUB_RUN_ID || 'Cycle 1',
  . . .
};

export default config;

Tip

When using Typescript config file, make sure to add the config file name in tsconfig.json file to use process.env in the config file.

In case if you are having config file in JSON / YAML format, then you can use the following syntax to set the values of the configuration options:

{
  "testCycle": "${GITHUB_RUN_ID:'Cycle 1'}",
}

Configure in CI / CD Pipeline

To generate the report in your CI / CD pipeline, you can use the mchr command in your pipeline script. For example, in case of GitLab CI / CD, you can use the following script:

# Run the tests
pnpm test

# Generate the report
mchr

Last updated on

On this page