0

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.

bababuba
  • 31
  • 1
  • 7
  • Did you use Jasmine to write test case? or other Test Framework like Cucumber, Mocha? – yong Mar 26 '18 at 23:01
  • @yong I'm using Jasmine – bababuba Mar 27 '18 at 05:52
  • You can read another thread: https://stackoverflow.com/questions/49313699/protractor-jasmine2-screenshot-reporter-not-generating-screenshots-in-the-requir/49316578#49316578 – yong Mar 27 '18 at 10:45

3 Answers3

1

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'"    
0

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');
});
Drew Royster
  • 120
  • 12
0

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.

bababuba
  • 31
  • 1
  • 7