jaffamoney
jaffamoney

Reputation: 31

CucumberJS/Protractor build result report not showing screenshot when run on Jenkins

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');
    });
    }

Upvotes: 0

Views: 279

Answers (1)

Ram Pasala
Ram Pasala

Reputation: 5231

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';”)

Upvotes: 1

Related Questions