Open tfnico opened 8 years ago
This works for me:
browser.takeScreenshot().then(function (png) {
var decodedImage = new Buffer(png, 'base64').toString('binary');
scenario.attach(decodedImage, 'image/png');
});
The packages are set like this:
"cucumber": "^0.10.2",
"gulp-protractor": "^2.1.0",
"gulp-protractor-cucumber-html-report": "^0.1.2",
"protractor-cucumber-framework": "^0.5.0",
@danyc Could you try upgrading cucumber and see if it breaks? I would try downgrading, but at dayjob we've moved back to cucumber-jvm again, so I won't be able to put more time in this.
Indeed, after upgrading, the screenshots are no longer visible in the report. The cucumber-js changelog shows that in 1.2.0 there was a bug fix related to encoding: https://github.com/cucumber/cucumber-js/blob/master/CHANGELOG.md#120-2016-06-24
Check the newest issue I raised, as the code you see there, does work.
For reference, that is #19.
@jaffamonkey's code works for me also, though I don't think it's the most elegant possible solution. The problem is that browser.takeScreenshot()
provides a string which is already base64 encoded. json_formatter then converts it to a Buffer and calls data: data.toString('base64')
Would be good if josn_formatter was smart enough to determine if attachement.getData()
was already base64 encoded.
It seems cucumber.js is now doing the encoding themselves when attaching pngs. I therefore had to decode twice to get the screenshot ending up viewable in the report:
More discussion on this here: https://github.com/cucumber/cucumber-js/issues/275
Here are the relevant packages I'm using:
I'm not sure which tool is doing the wrong thing here, as I don't understand Cucumber's conventions on how to encode embeddings...