量角器未使用Cucumber Reporter捕获屏幕截图

时间:2019-12-19 14:10:48

标签: protractor cucumber

我正在使用带有Cucumber的Protractor来测试角度应用程序,用于报告我正在使用“ cucumber-html-reporter”,我无法在报告中捕获屏幕快照,并且也无法保存在给定的文件夹中

reporter.js

const reporter = require("cucumber-html-reporter");
cucumberReporteroptions = {
  theme: "bootstrap",
  //jsonFile: targetJson,
  jsonDir: targetjsonDir,
  output: htmlReports + "/cucumber_reporter"+datetime+".html",
  reportSuiteAsScenarios: true,
  storeScreenshots:true,
  screenshotsDirectory:htmlReports +'/screenshots',
  reportSuiteAsScenarios:true,
  launchReport:true,
  ignoreBadJsonFile:true
};

class Reporter {

  static createHTMLReport() {
    try {
      reporter.generate(cucumberReporteroptions); //invoke cucumber-html-reporter
    } catch (err) {
      if (err) {
        console.log("Failed to save cucumber test results to json file.");
        console.log(err);
      }
    }
  }

hooks.js

 After(function(scenario) {
            const attach = this.attach; 
            return browser.takeScreenshot().then(function(png) {
              const decodedImage = new Buffer(png, "base64");
              return attach(decodedImage, "image/png");
            });
        });

1 个答案:

答案 0 :(得分:0)

可以从侧面快速检查一下,以确保正确调用了报告程序:

onPrepare: () => {
    browser.ignoreSynchronization = true;
    browser.manage().window().maximize();
    Reporter.createDirectory(jsonReports);
},
cucumberOpts: {
    compiler: "ts:ts-node/register",
    format: "json:./reports/json/cucumber_report.json",
    require: ["../../typeScript/stepdefinitions/*.js", "../../typeScript/support/*.js"],
    strict: true,
},

onComplete: () => {
    Reporter.createHTMLReport();
},

您可以尝试一下吗

defineSupportCode(({After}) => {
    After(function(scenario) {
        if (scenario.isFailed()) {
        var attach = this.attach; 
        return browser.takeScreenshot().then(function(png) {
        var decodedImage = new Buffer(png, "base64");
        return attach(decodedImage, "image/png");
      });
     }
   });
});

莱姆知道这是怎么回事!