简体   繁体   中英

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.

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
};

Your test script is running the command cucumber-js features/**/*.feature --require-module ts-node/register --require test.setup.ts --require step-definitions/**/*.ts --parallel 1 -f json:report/report.json
and the generate report command node report.js

As you are using && the generate report command will run only if the previous command was successful. As the test fails cucumber-js exit code is 1 and the generate report command will not be executed.

Solution: replace && with ; and it should generate the report regardless of the result of the tests.

"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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM