如果我的方案失败,则JSON报告无法生成。但对于传递方案,我可以看到JSON报告。
请找到我的配置文件,如下所示。
在评论提示控制台中,我可以看到失败消息:
W / launcher - 忽略未捕获的错误AssertionError:预期false等于true
E / launcher - BUG:启动器退出,剩下1个任务
答案 0 :(得分:0)
您可以使用钩子保存报告,因此不要从protractor.conf.js
文件生成文件,而是使用黄瓜钩子。
钩子看起来像这样
<强> reportHook.js:强>
const cucumber = require('cucumber');
const jsonFormatter = cucumber.Listener.JsonFormatter();
const fs = require('fs-extra');
const jsonFile = require('jsonfile');
const path = require('path');
const projectRoot = process.cwd();
module.exports = function reportHook() {
this.registerListener(jsonFormatter);
/**
* Generate and save the report json files
*/
jsonFormatter.log = function(report) {
const jsonReport = JSON.parse(report);
// Generate a featurename without spaces, we're gonna use it later
const featureName = jsonReport[0].name.replace(/\s+/g, '_').replace(/\W/g, '').toLowerCase();
// Here I defined a base path to which the jsons are written to
const snapshotPath = path.join(projectRoot, '.tmp/json-output');
// Think about a name for the json file. I now added a featurename (each feature
// will output a file) and a timestamp (if you use multiple browsers each browser
// execute each feature file and generate a report)
const filePath = path.join(snapshotPath, `report.${featureName}.${new Date}.json`);
// Create the path if it doesn't exists
fs.ensureDirSync(snapshotPath);
// Save the json file
jsonFile.writeFileSync(filePath, jsonReport, {
spaces: 2
});
};
}
您可以将此代码保存到文件reportHook.js
,然后将其添加到cucumberOpts:.require
,以便在代码中看起来像这样
cucumberOpts: {
require: [
'../step_definitions/*.json',
'../setup/hooks.js',
'../setup/reportHook.js'
],
....
}
即使步骤/方案失败,也应该生成报告文件。
希望有所帮助