Reputation: 31
I'm new to Protractor and trying to figure out how can I take screenshot when my tests are failing.. I've already tried to use protractor-jasmine2-screenshot-reporter but it does not seem to work.. Anyone uses a different plugin that works? or have any idea why the above one doesn't?
Thanks.
Upvotes: 0
Views: 2959
Reputation: 127
Run following commands to install Protractor html ScreenShot report
$ npm install protractor-html-screenshot-reporter --save-dev
after this update your Protractor.conf.js with
var Jasmine2HtmlReporter = require('/usr/lib/node_modules/protractor-jasmine2-html-reporter');
onPrepare() {
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: 'Mention location of your test result',
fileName: 'Test Result',
fileNameDateSuffix: true ,
takeScreenShotsOnlyForFailedSpecs: true,
}),
new SpecReporter({ spec: { displayStacktrace: true } })
);
In this location it will create a seprate folder called "ScreenShots" and saves all the screenshot here
"savePath: 'Mention location of your test result'"
Upvotes: 1
Reputation: 31
Eventually I've found some gitHub repo that helped me. If anyone encounters problems resolving the issue, you can use :
https://gist.github.com/jlouros/190d654850f8e2ed7b51ed6267f30400
Works great for me.
Upvotes: 0
Reputation: 120
From http://www.protractortest.org/#/debugging#taking-screenshots
// at the top of the test spec:
var fs = require('fs');
// ... other code
// abstract writing screen shot to a file
function writeScreenShot(data, filename) {
var stream = fs.createWriteStream(filename);
stream.write(new Buffer(data, 'base64'));
stream.end();
}
// ...
// within a test:
browser.takeScreenshot().then(function (png) {
writeScreenShot(png, 'exception.png');
});
Upvotes: 0