量角器测试失败如何截图?

How to take a screenshot when a protractor test fails?

我是 Protractor 的新手,想弄清楚如何在测试失败时截取屏幕截图。我已经尝试使用 protractor-jasmine2-screenshot-reporter 但它似乎不起作用。 . 有人使用其他有效的插件吗?或者知道为什么上面的没有?

谢谢。

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

最终我找到了一些对我有帮助的 gitHub 回购协议。 如果有人在解决问题时遇到问题,您可以使用:

https://gist.github.com/jlouros/190d654850f8e2ed7b51ed6267f30400

非常适合我。

运行 按照命令安装 Protractor html 截屏报告

 $ npm install protractor-html-screenshot-reporter --save-dev

在此更新后,您的 Protractor.conf.js 为

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

在此位置,它将创建一个名为 "ScreenShots" 的单独文件夹,并将所有屏幕截图保存在此处

 "savePath: 'Mention location of your test result'"