【问题标题】:How to take a screenshot when a protractor test fails?量角器测试失败时如何截取屏幕截图?
【发布时间】:2018-09-04 20:47:13
【问题描述】:

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

谢谢。

【问题讨论】:

标签: angularjs selenium protractor angularjs-e2e


【解决方案1】:

运行以下命令安装 Protractor html ScreenShot 报告

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 我个人使用 Cucumber,但我认为您更喜欢更通用的答案
    【解决方案3】:

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

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

    非常适合我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 2020-10-11
      • 2019-10-02
      相关资源
      最近更新 更多