0

I am using CucumberJS/Protractor, and successfully manage to generate html report with screenshots upon failure (after encoding screenshot image to base64). This is on local machine. However Jenkins does not insert this image into the report, due to Content Security settings. As of course, I don't want to compromise security on the build server, is there a way round this issue? The save screenshot code is below.

if (scenario.isFailed()) {
    browser.takeScreenshot().then(function (png) {
    var decodedImage = new Buffer(png.replace(/^data:image\/(png|gif|jpeg);base64,/,''), 'base64');
    scenario.attach(decodedImage, 'image/png');
    });
    }
jaffamoney
  • 31
  • 8

1 Answers1

1

You could try something like this-

 if (scenario.isFailed()) {
     browser.takeScreenshot().then(function (base64png) {
     var decodedImage = new Buffer(base64png, 'base64').toString('binary')
     scenario.attach(decodedImage, 'image/png');
     });
     }

If you want to disable the content security settings you can disable them in your script console (manage jenkins) by executing following two scripts-

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';")

System.setProperty("jenkins.model.DirectoryBrowserSupport.CSP", "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';”)
Ram Pasala
  • 4,931
  • 3
  • 16
  • 26
  • Generating screenshot is not problem - in fact the code you posted does not work in current CucumberJS version. It results in corrupted image. The problem is specifically related to insertion of image into report, on Jenkins build server. Something that works fine, when I run locally. The issue Jenkins reports is the action of inserting image into HTML is against Content Security settings. I was asking for options how to deal with this, not how to generate a screenshot. – jaffamoney Aug 05 '16 at 13:48
  • It works for me and I am using latest cucumberjs anyways even i faced the `content security settings` issue with the new jenkins versions they have put restrictions only solution i could think of is disable them and since you told its in your local machine i think it won't cause any issues of security. just check my update answer on how to disable them. – Ram Pasala Aug 05 '16 at 15:40