Javascript I';m getting找不到模块';量角器-jasmine2-html-reporter';

Javascript I';m getting找不到模块';量角器-jasmine2-html-reporter';,javascript,json,jasmine,protractor,Javascript,Json,Jasmine,Protractor,我尝试使用“'dragrator-jasmine2-html-reporter'”生成报告,但我发现模块未找到异常,错误代码为5。谁能帮我一下吗 Config.js var Jasmine2HtmlReporter=require('protractor-jasmine2-html-reporter'); exports.config = { directConnect : true, capabilities:{ 'browse

我尝试使用“'dragrator-jasmine2-html-reporter'”生成报告,但我发现模块未找到异常,错误代码为5。谁能帮我一下吗

Config.js

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

exports.config = {
        directConnect : true,
        capabilities:{
                'browserName':'chrome'
        },
          framework: 'jasmine2',
          seleniumAddress: 'http://localhost:4444/wd/hub',
          specs: ['ProtractorTest/PageObjectMain.js'],
          jasmineNodeOpts:{
            defaultTimeoutInterval : 30000  
          },

          onPreapre:function(){
              jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
                  savePath:"./test-results/report"
              }));
          },
        }
错误日志

[14:54:53] E/configParser - Error code: 105
[14:54:53] E/configParser - Error message: failed loading configuration file ReportConfig.js
[14:54:53] E/configParser - Error: Cannot find module 'protractor-jasmine2-html-reporter'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (H:\workspace\Protractor_tutorials\ReportConfig.js:1:88)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
[14:54:53]E/configParser-错误代码:105
[14:54:53]E/configParser-错误消息:加载配置文件ReportConfig.js失败
[14:54:53]E/configParser-错误:找不到模块'Gradurator-jasmine2-html-reporter'
在Function.Module.\u解析文件名(Module.js:538:15)
在Function.Module.\u加载(Module.js:468:25)
at Module.require(Module.js:587:17)
根据需要(内部/module.js:11:18)

在对象上。

看起来您还没有安装Drugator-jasmine2-html-reporter 转到安装包的文件夹(node_modules文件夹)并运行:

npm install protractor-jasmine2-html-reporter

在使用量角器时,您需要确保的事情很少

1.在我的例子中,在为reporter创建变量时,不要直接传递reporter name,而是尝试传递reporter模块的完整路径。。希望这能奏效 例如:


2.确保运行扩展名为.js的正确配置文件。

通过运行
npm audit
哪个npm
命令,尝试检查
node\u modules
目录的位置。主要的问题是,应该跟踪安装
node_模块
的路径,并且像
npm install dragor-jasmine2-html-reporter这样的新模块可以安装在该路径中

安装,而无需为我保存devworked

全球安装

npm install -g  protractor-jasmine2-html-reporter
运行下面的命令,将量角器和jasmine2 html reporter链接到未生成问题的aovid报告。请看《少女索特》中的回答

npm链接量角器-jasmine2-html-reporter

还要添加此导入以及精确节点模块的路径,以避免在windows 10中出现错误

var Jasmine2HtmlReporter = require('C:/Users/sam/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
完整的conifg,js,在windows 10中为我工作,如下所示

//protractor jasminreporterconfig.js
//Add this import with path to exact node module to avoid the error 
var Jasmine2HtmlReporter = require('C:/Users/sam/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');

exports.config = {
  framework: 'jasmine',

 capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--start-maximized" ]
         }
    },

      onPrepare: function() {
          jasmine.getEnv().addReporter(
            new Jasmine2HtmlReporter({
           takeScreenshots: true,// By default this is enabled Default is true
           takeScreenshotsOnlyOnFailures: false, // Default is false (So screenshots are always generated)
           cleanDestination: true, // if false, will not delete the reports or screenshots before each test run.Default is true
           showPassed: true,//default is true This option, if false, will show only failures.
           fileName: 'MyRepoDemo', //We can give a prefered file name .
           savePath: 'myproreports',//Reports location it will automatically generated
           screenshotsFolder: 'screenshotsloc' //Screenshot location it will create a folder inside myproreports
            })
          );
       },

  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['src/com/sam/scriptjs/nonangularstackscript.js']

}

如果希望将包自动添加到您的
包.json
,请添加
--save
参数:
npm install gragrator-jasmine2-html-reporter--save
@Sanja和Bouke,我安装了jasmine2 reporter,但根据您的建议,我删除了它,并使用相同的命令再次安装了它。。仍然收到相同的错误。请参阅附件中的文件夹。请展开您的答案。也许有一些命令和预期的结果可以帮助解决这个问题。此外,请查看您的格式,并尝试将命令、名称等格式化为代码。我为你做了一些。
//protractor jasminreporterconfig.js
//Add this import with path to exact node module to avoid the error 
var Jasmine2HtmlReporter = require('C:/Users/sam/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');

exports.config = {
  framework: 'jasmine',

 capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--start-maximized" ]
         }
    },

      onPrepare: function() {
          jasmine.getEnv().addReporter(
            new Jasmine2HtmlReporter({
           takeScreenshots: true,// By default this is enabled Default is true
           takeScreenshotsOnlyOnFailures: false, // Default is false (So screenshots are always generated)
           cleanDestination: true, // if false, will not delete the reports or screenshots before each test run.Default is true
           showPassed: true,//default is true This option, if false, will show only failures.
           fileName: 'MyRepoDemo', //We can give a prefered file name .
           savePath: 'myproreports',//Reports location it will automatically generated
           screenshotsFolder: 'screenshotsloc' //Screenshot location it will create a folder inside myproreports
            })
          );
       },

  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['src/com/sam/scriptjs/nonangularstackscript.js']

}