I tried with the below code
to take screenshot
and save it locally. But, I want to embed the screenshot to the cucumber HTML report
(which is generated by Jenkins
using json
file).
What would be the code I should add here for embedding
which should reflect in my json
report file to fetch that link in HTML
report? Please suggest.
My code:
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();
});