仅在使用诱惑报告器失败时捕获屏幕截图



我 https://github.com/allure-framework/allure-jasmine 休学即使通过,我运行的每个规范都会得到屏幕截图。我想实现的是,只有在测试失败时才会捕获屏幕截图。

添加屏幕截图进行测试(这是我的 conf.js 的样子(

  onPrepare: function () {
    var AllureReporter = require('jasmine-allure-reporter');
    jasmine.getEnv().addReporter(new AllureReporter());
    jasmine.getEnv().afterEach(function(done){
      browser.takeScreenshot().then(function (png) {
        allure.createAttachment('Screenshot', function () {
          return new Buffer(png, 'base64')
        }, 'image/png')();
        done();
      })
    });
  }

以下脚本可能会对您有所帮助,您需要在 protractor.conf.js 上检查 specDone 时的状态,请参见下文:

let addScreenShots = new function () {
    this.specDone = function (result) {        
        if (result.status === "failed") {
            browser.takeScreenshot().then(function (png) {
                allure.createAttachment('Screenshot', function () {
                    return new Buffer(png, 'base64')
                }, 'image/png')();
            });
        }
    };
}
exports.config = {
    ...
    jasmine.getEnv().addReporter(addScreenShots);
    jasmine.getEnv().addReporter(new AllureReporter({
        allureReport: {
            resultsDir: './test-results/results/'
        }
    }));
    ...
}

相关内容

最新更新