无法使用“ filename:”更改“ protractor-jasmine2-html-reporter”中的文件名

时间:2019-12-17 14:00:41

标签: javascript jasmine protractor jasmine-reporters

我正在使用“'protractor-jasmine2-html-reporter”为我的E2E测试用例生成报告。 我需要每次运行来创建一个新的报告html文件。

现在,每次运行测试套件时,“ htmlReport.html”文件都会被覆盖

尝试在“文件名:”末尾添加添加moment.js,但名称未从“ htmlReport.html”更改

1 个答案:

答案 0 :(得分:1)

我尝试通过将日期添加到onComplete的TestConfig对象中的outputFilename的outFilename中,它运行良好,并使用当前日期创建html。

这是它的样子

  onComplete: function() {
    var browserName, browserVersion;
    var capsPromise = browser.getCapabilities();

    capsPromise.then(function(caps) {
      browserName = caps.get('browserName');
      browserVersion = caps.get('version');
      platform = caps.get('platform');

      var HTMLReport = require('protractor-html-reporter-2');

      let current_datetime = new Date()
      let formatted_date = current_datetime.getFullYear() + "_" + (current_datetime.getMonth() + 1) + "_" + current_datetime.getDate() + " " + current_datetime.getHours() + ":" + current_datetime.getMinutes() + ":" + current_datetime.getSeconds()
      let fD1 = formatted_date.replace(" ","_");
      let fD2 = fD1.replace(":","_").replace(":","_");

      testConfig = {
        reportTitle: 'Protractor Test Execution Report',
        outputPath: './reports',
        outputFilename: 'htmlReport_' + fD2,
        screenshotPath: './reports/screenshots',
        testBrowser: browserName,
        browserVersion: browserVersion,
        modifiedSuiteName: true,
        screenshotsOnlyOnFailure: true,
        testPlatform: platform
      };
      new HTMLReport().from('./Results/xmlresults-test1.xml', testConfig);
    });
  }

希望这会有所帮助!