node.js - 不能使用 var HtmlReporter = require ('protractor-html-screenshot-reporter' )

标签 node.js npm protractor

我需要在 Protractor 中生成测试报告。我浏览了一些教程,但这些教程对我来说并不清楚。

当我尝试安装 npm 时,出现以下错误。

enter image description here

运行后,将创建名为 node_modules 的文件夹。但是,我不明白为什么我无法安装 npm。请帮忙。

-编辑-

我正在使用this生成 Protractor 报告的教程。

我将 var HtmlReporter = require('protractor-html-screenshot-reporter') 添加到我的 conf.js 这是我的完整文件。

// conf.js
exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['invoice.js'],
  capabilities: {
    browserName: 'chrome',
  },
  jasmineNodeOpts: {
    showColors: true, // Use colors in the command line report.
  }

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

      var reporter=new HtmlReporter({
        baseDirectory: './protractor-result', // a location to store screen shots.
        docTitle: 'Protractor Demo Reporter',
        docName:    'protractor-demo-tests-report.html'
    });

    exports.config = {
        seleniumAddress: 'http://localhost:4444/wd/hub',
        specs: ['invoice.js'],

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

发生以下错误。

enter image description here

请告诉我该怎么做。提前致谢。

最佳答案

您的 conf.js 格式错误 - 您无法在对象定义中定义变量。它应该看起来像这样:

var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter = new HtmlReporter({
    baseDirectory: './protractor-result', // a location to store screen shots.
    docTitle: 'Protractor Demo Reporter',
    docName: 'protractor-demo-tests-report.html'
});

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['invoice.js'],
  capabilities: {
    browserName: 'chrome',
  },
  jasmineNodeOpts: {
    showColors: true, // Use colors in the command line report.
  },
  onPrepare: function() {
      jasmine.getEnv().addReporter(reporter);
  }
}

请注意,我从未使用过 Protractor,因此我无法保证这是一个有效的配置,但它应该可以对您的语法错误进行排序。

关于node.js - 不能使用 var HtmlReporter = require ('protractor-html-screenshot-reporter' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35913632/

相关文章:

MySQL 查询 10 个表(Sequelize 或 Raw Query)

node.js - typescript 错误 :Cannot read property 'length' of undefined while running ng-serve

node.js - mongodb/mongoose addToSet 将对象添加到具有相同 id 的数组

node.js - 安装具有收缩包装的软件包时,NPM 安装在成功退出时不会删除/tmp

node.js - JSLint,全局禁用规则

node.js - 如何删除旧版本的nodejs?

javascript - 为什么当我使用 Protractor 写文本时它不能正常工作

node.js - 通过 Laravel Forge 服务器上的地址访问 Node.js 应用程序

javascript - 无法使用 Protractor 从 mailosaur 获取值,尽管使用 node.js 也是如此

javascript - 如何计算 gettext 值直到达到一定数量的这些值