mrooding / gulp-protractor-cucumber-html-report

Generate html report from JSON file returned by cucumber-js json formatter
MIT License
12 stars 11 forks source link

Screenshots end up being base64 encoded twice #18

Open tfnico opened 8 years ago

tfnico commented 8 years ago

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:

browser.takeScreenshot().then(function (stream) {
        //double decode the image to workaround the double encoding that cucumber.js+report does
        scenario.attach(new Buffer(new Buffer(stream, 'base64'), 'base64'), 'image/png', function (err) {
          callback(err);
        });
      });

More discussion on this here: https://github.com/cucumber/cucumber-js/issues/275

Here are the relevant packages I'm using:

"cucumber": "^1.2.1",
"gulp-protractor": "^2.4.0",
"gulp-protractor-cucumber-html-report": "^0.1.2",
"protractor": "^4.0.0",
"protractor-cucumber-framework": "^0.6.0",

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...

danyc commented 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",
tfnico commented 8 years ago

@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.

danyc commented 8 years ago

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

jaffamonkey commented 8 years ago

Check the newest issue I raised, as the code you see there, does work.

tfnico commented 8 years ago

For reference, that is #19.

nalbion commented 8 years ago

@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.