想要使用Jasmine HTML报告器和Protractor HTML报告器

时间:2016-06-27 04:41:47

标签: protractor

我尝试使用Jasmine HTML报告器和Protractor HTML报告器。

我的Config.js代码看起来像这样

    var HtmlReporter = require('protractor-html-screenshot-reporter');
    jasmine.getEnv().addReporter(new HtmlReporter({
    baseDirectory: '/protractor-result', 
    docTitle: 'Protractor Demo Reporter',
    docName:    'protractor-demo-tests-report.html'
}));


var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');

jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
    savePath: '../Report/HTML/',
    showSummary: true,
    showQuickLinks: true,
    showConfiguration: true,
    screenshotsFolder: 'images',
    takeScreenshots: true,
    takeScreenshotsOnlyOnFailures: true,
    fixedScreenshotName: true,
    ignoreSkippedSpecs: true,
    consolidate: true,
    consolidateAll: true,
    preserveDirectory: true,
    reportTitle: 'Protractor-Execution-Report-' + timeStamp
}));

我能够看到Jasmine生成的HTML报告,但仍然无法看到Protractor生成的HTML报告。如果我尝试的是不真实的东西,请纠正我。

任何帮助都将不胜感激。

4 个答案:

答案 0 :(得分:2)

protractor-html-screenshot-reporter jasmine 2 不兼容,最新版本的量角器默认使用jasmine 2,而是切换到

  

量角器-jasmine2-HTML - 报告

答案 1 :(得分:1)

您需要将这些行放在protractor.config.js文件的onPrepare部分中:

var HtmlReporter = require('protractor-html-screenshot-reporter');
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');


exports.config = {
   //other stuff

   onPrepare: function() {
      // Add a screenshot reporter and store screenshots to `/tmp/screnshots`: 
      jasmine.getEnv().addReporter(new HtmlReporter({
         baseDirectory: '/tmp/screenshots'
         //...
      }));
      jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
         savePath: '../Report/HTML/'
         //...
      }));
   }
}

答案 2 :(得分:1)

我使用protractor-jasmine2-screenshot-reporterprotractor-jasmine2-html-reporter来处理这个问题,这是我的配置文件protractor.conf.js,希望它能为您提供帮助。

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');

var jasmine2HtmlReporter =  new Jasmine2HtmlReporter({
  savePath: 'report/e2e/protractor-jasmine2-html-reporter/',
  filePrefix: 'index',
  screenshotsFolder: 'screenshots'
});

var htmlScreenshotReporter = new HtmlScreenshotReporter({
  dest: 'report/e2e/protractor-jasmine2-screenshot-reporter/',
  filename: 'index.html'
});

exports.config = {
  allScriptsTimeout: 11000,

  specs: [
    '*.e2e.js'
  ],

  capabilities: {
    'browserName': 'chrome'
  },

  baseUrl: 'http://localhost:8080/app/',

  framework: 'jasmine',

  jasmineNodeOpts: {
    defaultTimeoutInterval: 30000,
    showColors: true
  },

  // Setup the report before any tests start
  beforeLaunch: function() {
    return new Promise(function(resolve){
      htmlScreenshotReporter.beforeLaunch(resolve);
    });
  },

  // Assign the test reporter to each running instance
  onPrepare: function () {
    jasmine.getEnv().addReporter(jasmine2HtmlReporter);
    jasmine.getEnv().addReporter(htmlScreenshotReporter);
  },

  // Close the report after all tests finish
  afterLaunch: function(exitCode) {
    return new Promise(function(resolve){
      htmlScreenshotReporter.afterLaunch(resolve.bind(this, exitCode));
    });
  }

};

有关详细信息,请参阅here

答案 3 :(得分:1)

我知道这已经很老了,但我遇到了一个问题,试图让jasmine-reporter和protractor-jasmine2-html-reporter工作,并且不喜欢我为了让他们工作而必须降级的想法。我发现protractor-jasmine2-html-reporter没有正确解析savePath,实际上是将报告文件夹输出放在protractor-jasmine2-html-reporter目录下,而不是我运行gulp的根目录。为了使这项工作正常,我最终使用 process.env.INIT_CWD 来获取最初的当前工作目录,该目录应该是您运行gulp的目录。希望这有助于某人。

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var jasmine2HtmlReporter = new Jasmine2HtmlReporter({
  savePath: process.env.INIT_CWD + '/report/e2e/',
  screenshotsFolder: 'images',
  takeScreenshots: true,
  takeScreenshotsOnlyOnFailures: true,
  fileName: 'index.html'
});

onPrepare: function () {
    jasmine.getEnv().addReporter(jasmine2HtmlReporter);
}