如何使用 Jasmine2 创建 Protractor 报告

How to create Protractor reports with Jasmine2

我最近开始使用 Protractor 库来测试 angularjs site.I 尝试使用以下 2 个库来创建 HTML 报告,但在这两种情况下我都遇到了错误

https://www.npmjs.com/package/protractor-jasmine2-html-reporterhttps://www.npmjs.com/package/protractor-jasmine2-screenshot-reporter.

平台:- Windows7

安装命令:- npm install -g protractor-jasmine2-html-reporter

错误:找不到模块 'protractor-jasmine2-html-reporter'

Config.js

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

var today = new Date(),
    timeStamp = today.getMonth() + 1 + '-' + today.getDate() + '-' + today.getFullYear() + '-' + today.getHours() + 'h-' + today.getMinutes() + 'm';

var reporter=new Jasmine2HtmlReporter({
    consolidateAll: true,
        savePath: 'target/screenshots',
        takeScreenshotsOnlyOnFailures: true,
         filePrefix: 'index -'+today
});

// An example configuration file.
exports.config = {
  directConnect: true,

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Framework to use. Jasmine 2 is recommended.
  framework: 'jasmine2',

  // Spec patterns are relative to the current working directly when
  // protractor is called.
  specs: ['../Test/SmokeTest.js'],



  // Options to be passed to Jasmine.
  jasmineNodeOpts: {
    showColors:true,
    defaultTimeoutInterval: 400000,
    isVerbose: true,
    includeStackTrace: true
  },

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

如果我遗漏了什么,请告诉我。 提前致谢。

您应该在需要时将完整路径添加到 protractor-jasmine2-html-reporter。尝试输入完整路径,然后 运行 测试脚本。这是一个示例 -

var Jasmine2HtmlReporter = require('/usr/local/lib/node_modules/protractor-jasmine2-html-reporter'); //sample for MAC

var Jasmine2HtmlReporter = require('c:/node_modules/protractor-jasmine2-html-reporter'); //sample for windows

根据计算机中安装的文件夹更新路径。如果你不知道你的 node_modules 安装在哪里,运行 下面的命令来获取它 -

npm link protractor-jasmine2-html-reporter

希望对您有所帮助。