我尝试使用以下内容code
将screenshot
其保存在本地。但是,我想将屏幕截图嵌入到cucumber HTML report
(Jenkins
使用json
文件生成)。
我应该在此处添加哪些代码embedding
应该反映在我的json
报告文件中以获取HTML
报告中的链接?请建议。
我的代码:
module.exports = function stepResultHooks() {
var fs = require('fs'), dir = 'features/screenShots/';
this.StepResult(function (event, callBack) {
var stepResult = event.getPayloadItem('stepResult'), step = stepResult.getStep();
if (stepResult.isFailed()) {
browser.takeScreenshot().then(function (png) {
browser.getCapabilities().then(function (capabilities) {
var browserName = capabilities.caps_.browserName;
var browserVersion = capabilities.caps_.version;
var stream, fname;
fname = 'Screenshot' + '_' + 'Failed Step' + '_' + step.getName() + '_' + browserName.toUpperCase()+'_'+browserVersion+'_' + new Date() + '.png';
fname = fname.replace(/"|'|\//g, '').replace(/\s|:|>/g, '_');
stream = fs.createWriteStream(dir + fname);
stream.write(new Buffer(png, 'base64'));
stream.end();
});
}).then(callBack);
} else callBack();
});