0
直到[email protected]
框架使用Cucumber 2
,我意识到我的黄瓜报表生成与一个Event Handler
钩测试执行后直接,如:生成测试执行与Nightwatch黄瓜嫁接黄瓜报告
const reporter = require("cucumber-html-reporter");
defineSupportCode(function({ registerHandler }) {
registerHandler("AfterFeature", function(features, callback) {
try {
var options = {
theme: "bootstrap",
jsonFile: "./reports/json_result/cucumber.json",
output: "./reports/json_result/cucumber_report.html",
reportSuiteAsScenarios: true,
launchReport: false,
metadata: {
"App Version": "0.0.3"
}
};
reporter.generate(options);
} catch (e) {
console.log(
"Report generation is not possible with the following message:"
);
console.log(e);
}
client.end();
callback();
});
});
但由于[email protected]
的框架使用Cucumber 3
和Event Handler
不再可用。现在我想使用AfterAll
函数Cucumber.js
,但是在执行AfterAll
函数时不会生成黄瓜json报告的内容。所以我得到异常reports/json_result/cucumber.json: Unexpected end of JSON input
,因为黄瓜json文件在这个时候是空的。我怎样才能在测试执行后生成一个黄瓜报告,如AfterAll
用于拆卸。
这里是我当前的代码:
const reporter = require("cucumber-html-reporter");
defineSupportCode(function({ AfterAll }) {
AfterAll(function(callback) {
try {
var options = {
theme: "bootstrap",
jsonFile: "./reports/json_result/cucumber.json",
output: "./reports/json_result/cucumber_report.html",
reportSuiteAsScenarios: true,
launchReport: false,
metadata: {
"App Version": "0.0.3"
}
};
reporter.generate(options);
} catch (e) {
console.log(
"Report generation is not possible with the following message:"
);
console.log(e);
}
client.end();
callback();
});
});