【问题标题】:I'm getting Cannot find module 'protractor-jasmine2-html-reporter'我得到找不到模块'protractor-jasmine2-html-reporter'
【发布时间】:2019-12-07 16:54:10
【问题描述】:

我尝试使用“'protractor-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)

我的 'Package.Json' 没有关于报告文件的任何详细信息。所以如果这是问题所在,请帮助我如何在 json 文件中配置它们。

【问题讨论】:

    标签: javascript json jasmine protractor


    【解决方案1】:

    在使用 Protractor Reporters 时,您需要确保的事项很少

    1.在我的情况下,在为记者创建变量而不是直接传递记者姓名时尝试传递记者模块的完整路径..这可能会奏效 例如:

    var Jasmine2HtmlReporter=require('C:/......./npm-modules/protractor-jasmine2-html-reporter');
    

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

    【讨论】:

      【解决方案2】:

      在没有保存开发的情况下安装。

      全局安装

      npm install -g  protractor-jasmine2-html-reporter
      

      运行以下命令将量角器和 jasmine2-html-reporter 链接到 aovid 报告未生成问题。请参阅 Girish Sortur 在How to create Protractor reports with Jasmine2 中的回答

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

      还要将此导入添加到确切节点模块的路径以避免 Windows 10 中的错误

      var Jasmine2HtmlReporter = require('C:/Users/sam/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
      

      如下所示,在 Windows 10 中为我工作的完整配置、js。

      //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']
      
      }
      

      【讨论】:

        【解决方案3】:

        你好像还没有安装 protractor-jasmine2-html-reporter 转到安装包的文件夹(node_modules 文件夹)并运行:

        npm install protractor-jasmine2-html-reporter
        

        【讨论】:

        • 如果希望包自动添加到您的package.json,然后添加--save 参数:npm install protractor-jasmine2-html-reporter --save
        • @Sanja 和 Bouke,我安装了 jasmine2-reporter,但根据您的建议,我删除并再次使用相同的命令安装.. 仍然出现相同的错误..
        • 请参考附件图片
        【解决方案4】:

        尝试通过运行npm auditwhich npm 命令来检查node_modules 目录的位置。主要是应该跟踪安装node_modules的路径,并且可以在该路径中安装像npm install protractor-jasmine2-html-reporter这样的新模块

        【讨论】:

        • 请扩展您的答案。也许有一些命令和预期的结果可以帮助解决问题。此外,请查看您的格式,并尝试将命令、名称等格式化为代码。我已经为你做了一些。
        猜你喜欢
        • 2018-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多