'Unable to generate Cucumber HTML reports on failure

I have created a project framework using Typescript and Cucumber BDD approach. The executions within the project are working and the cucumber html reports are also getting generated when executions are getting passed, but when the things are failing due to some reason(whether assertion reason in my case) the reports are not getting generated within the specified folder.

Below are some key points to look upon;

  • I am using package.json test module perform my executions.

{
  "name": "sampleprojectplaywright",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    
    "test": "cucumber-js features/**/*.feature --require-module ts-node/register --require test.setup.ts --require step-definitions/**/*.ts --parallel 1 -f json:report/report.json && node report.js && type report/report.json"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@cucumber/cucumber": "^7.3.2",
    "@playwright/test": "^1.19.1",
    "@types/mkdirp": "^1.0.2",
    "@types/node": "^17.0.18",
    "cucumber-html-reporter": "^5.3.0",
    "cucumber-junit": "^1.7.1",
    "cucumberjs-junitxml": "^1.0.0",
    "fs-extra": "^3.0.1",
    "mkdirp": "^0.5.1",
    "mkdirp-promise": "^5.0.1",
    "multiple-cucumber-html-reporter": "^1.19.0",
    "playwright": "^1.19.1",
    "sanitize-filename": "^1.6.1",
    "ts-node": "^10.5.0",
    "typescript": "^4.5.5"
  }
}
  • Below is the code snippet for report.js file(that is generating the reports in the mentioned folders over there)

const reporter = require("cucumber-html-reporter");
const options = {
  theme: "bootstrap",
  jsonFile: "report/report.json",
  output: "report/cucumber-html-report.html",
  reportSuiteAsScenarios: true,
  launchReport: false,
};
reporter.generate(options);

A point to consider is that report.json is getting created in case of failure also but only html report isn't getting created on failure.



Solution 1:[1]

In order to generate html reports in failure please try to add below code in your cucumber.js file.

In common add "--require report.js", This helps in creating in both passed and failed cases

For reference

const common = --require runner/hooks.js --require features/support/steps.js --require report.js;

module.exports = {
default: ${common} features/**/*.feature
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1