I want to create cucumber html reports and I am new to Node JS and I tried searching for it and I used the following
this.registerHandler('AfterFeatures', function(callback) {
try {
var options = {
theme: "bootstrap",
jsonFile: "/report/cucumber.json",
output: "/report/cucumber_report.html",
reportSuiteAsScenarios: true,
launchReport: true,
metadata: {
"App Version": "0.0.1"
}
};
reporter.generate(options);
} catch (e) {
console.log(e);
}
callback();
});
But when I run my code, The cucumber feature scenarios gets executed and it finally gives me an error stating,
Unable to parse cucumberjs output into json: '/report/cucumber.json' { Error: /report/cucumber.json: ENOENT: no such file or directory, open '/report/cucumber.json'
at Object.fs.openSync (fs.js:652:18)
at Object.fs.readFileSync (fs.js:553:33)
at Object.readFileSync (/Users/sarav/Documents/GitHub/automationtests/node_modules/jsonfile/index.js:67:22)
at isValidJsonFile (/Users/sarav/Documents/GitHub/automationtests/node_modules/cucumber-html-reporter/lib/reporter.js:404:48)
at Object.generate (/Users/sarav/Documents/GitHub/automationtests/node_modules/cucumber-html-reporter/lib/reporter.js:426:9)
at Object.generateReport [as generate] (/Users/sarav/Documents/GitHub/automationtests/node_modules/cucumber-html-reporter/index.js:30:21)
at /Users/sarav/Documents/GitHub/automationtests/features/support/hooks.js:49:22
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/report/cucumber.json' }
Do the above code automatically generates .json and .html file or we need to manually create a .json file and converts that into a html report.
I have worked on Java and it automatically creates the json and html reports at the end the execution.
As this is very new I am not able to figure out whats the missing part
Thanks
Your code to generate HTML report will expect the json file: /report/cucumber.json had been exist.
So you need other code to help to generate the json file during test running, I will give code used in my project for your reference.
Note: below code can only work on Cucumber 1, can't work on Cucumver 2, below is the version I used:
1) cucumber-json-report.js to generate Cucumber JSON report during running.
2) screenshot.js to take screenshot when failure
3) cucumber-html-report.js to generate Cucumber HTML report after all features running end.
4) Protractor conf.js to include above three files in cucumberOpts.require