Ped*_*pez 13 reporting report cucumber protractor cucumberjs
我正在使用Protractor和Cucumber(js).我想生成报告文件,就像使用Cucumber-JVM版本一样.我看过使用Protractor和Jasmine的例子,但实际上没有使用Cucumber.
使用此配置时如何生成报告?
最终目标是在Jenkins或其他任何地方发布此报告(如果它们是直接在HTML中生成的).
谢谢!
Ped*_*pez 11
使用最新版本的量角器(从1.5.0版开始),您现在可以生成JSON报告.当我在7个月前问过这个问题时,那个功能不存在.
您需要做的就是将它添加到protractor-config.json文件中.
resultJsonOutputFile: 'report.json'
Run Code Online (Sandbox Code Playgroud)
其中report.json是输出文件的位置.
一旦你有了,你可以使用protractor-cucumber-junit(https://www.npmjs.com/package/protractor-cucumber-junit),cucumberjs-junitxml(https://github.com/sonyschan/cucumberjs-junitxml)或类似的东西将JSON文件转换为Jenkins可以显示的有效XML文件.
$ cat report.json | ./node_modules/.bin/cucumber-junit > report.xml
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
您可以使用cucumber-html-report将json报告转换为HTML.将cucumber-html-report添加到您的项目中
$ npm install cucumber-html-report --save-dev
Run Code Online (Sandbox Code Playgroud)
如果你使用量角器,你可以将以下代码添加到hooks.js
var outputDir = 'someDir';
this.After(function(scenario, callback) {
if (scenario.isFailed()) {
browser.takeScreenshot().then(function(base64png) {
var decodedImage = new Buffer(base64png, 'base64').toString('binary');
scenario.attach(decodedImage, 'image/png');
callback();
}, function(err) {
callback(err);
});
} else {
callback();
}
});
var createHtmlReport = function(sourceJson) {
var CucumberHtmlReport = require('cucumber-html-report');
var report = new CucumberHtmlReport({
source: sourceJson, // source json
dest: outputDir // target directory (will create if not exists)
});
report.createReport();
};
var JsonFormatter = Cucumber.Listener.JsonFormatter();
JsonFormatter.log = function(string) {
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
var targetJson = outputDir + 'cucumber_report.json';
fs.writeFile(targetJson, string, function(err) {
if (err) {
console.log('Failed to save cucumber test results to json file.');
console.log(err);
} else {
createHtmlReport(targetJson);
}
});
};
this.registerListener(JsonFormatter);
Run Code Online (Sandbox Code Playgroud)