【问题标题】:Protractor error 105 when trying to run spec.js尝试运行 spec.js 时量角器错误 105
【发布时间】:2020-07-12 04:13:51
【问题描述】:

我的量角器工作正常,更新后它无法打开一个简单的规范文件,它总是给出 thsi 错误。我搜索了一个解决方案,但找不到一个 conf 和 spec 文件是量角器站点本身的示例,我粘贴下面的错误希望你能提供帮助。提前致谢

conf.js 错误

[09:10:06] E/configParser - error code: 105
[09:10:06] E/configParser - description: failed loading configuration file spec.js

C:\Users\y\AppData\Roaming\npm\node_modules\protractor\built\configParser.js:130

throw new exitCodes_1.ConfigError(logger, 'failed loading configurat
ion file ' + filename);
            ^
Error
    at ConfigError.ProtractorError (C:\Users\y\AppData\Roaming\npm\node_modules\protractor\built\exitCodes.js:10:22)
    at new ConfigError (C:\Users\y\AppData\Roaming\npm\node_modules\protractor\built\exitCodes.js:26:16)
    at ConfigParser.addFileConfig (C:\Users\y\AppData\Roaming\npm\node_modules\protractor\built\configParser.js:130:19)
    at Object.initFn [as init] (C:\Users\y\AppData\Roaming\npm\node_modules\protractor\built\launcher.js:94:22)
    at Object.<anonymous> (C:\Users\y\AppData\Roaming\npm\node_modules\protractor\built\cli.js:130:10)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)

conf 和 spec 文件是来自站点的示例文件

conf.js:

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js']
}

spec.js

describe('Protractor Demo App', function() {
  it('should have a title', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');

    expect(browser.getTitle()).toEqual('Super Calculator');
  });
});

【问题讨论】:

  • 您可以发布您的配置(编辑问题并将其包含在其中)吗?谢谢。
  • 我编辑了我正在回复的帖子,以防你没有检查
  • 您可以打开 C:\Users\y\AppData\Roaming\npm\node_modules\protractor\built\configParser.js:130 并在 catch 中输入 logger.error(e) 示例:catch (e) { logger.error(e); throw new exitCodes_1.ConfigError(logger, 'failed loading configuration file ' + filename); } 应该打印出类似 E/configParser - { [Error: Cannot find module 'ts-node/register'] code: 'MODULE_NOT_FOUND' } 的内容
  • 错误是说它无法使用带有配置的模块加载文件。这是按设计工作的。错误消息:E/configParser - description: failed loading configuration file spec. js 应该有助于弄清楚发生了什么。 1. 配置错误, 2. 无法加载文件。有人指出(如下)您正在加载规范文件而不是配置文件。
  • 我解释说我加载了 conf 文件,它给出了那个错误,但现在工作正常,我在上面运行多个 e2e 测试

标签: protractor


【解决方案1】:

根据@jtzero 的说法,问题在于配置解析器在加载配置文件时屏蔽了实际的错误消息。

根据您是作为全局还是从文件夹运行 Protractor,在第 13 行打开 (C:\Users\y\AppData\Roaming\npm\)node_modules\protractor\built\configParser.js ‌​0。 在那里你可以添加logger.error(e); 例如:

    /**
     * Public function specialized towards merging in a file's config
     *
     * @public
     * @param {String} filename
     */
    ConfigParser.prototype.addFileConfig = function (filename) {
        if (!filename) {
            return this;
        }
        var filePath = path.resolve(process.cwd(), filename);
        var fileConfig;
        try {
            fileConfig = require(filePath).config;
        }
        catch (e) {
            logger.error(e);
            throw new exitCodes_1.ConfigError(logger, 'failed loading configuration file ' + filename);
        }
        if (!fileConfig) {
            throw new exitCodes_1.ConfigError(logger, 'configuration file ' + filename + ' did not export a config object');
        }
        fileConfig.configDir = path.dirname(filePath);
        this.addConfig_(fileConfig, fileConfig.configDir);
        return this;
    };

这将在输出中报告错误。就我而言,这是对require() 的失败调用:

[10:36:29] E/configParser - { [Error: Cannot find module 'phantomjs'] code: 'MODULE_NOT_FOUND' }

报告的 GitHub 问题 #3301:https://github.com/angular/protractor/issues/3301

更新
Protractor 4.0 将包含针对此问题的修复程序,以报告带有堆栈跟踪的屏蔽错误消息。

【讨论】:

  • 按照您的建议编辑文件并没有改变我的日志输出,但它确实给了我一个想法。我打开node 并尝试require() REPL 中的conf 文件并得到了我正在寻找的错误。我缺少一个节点模块。
  • @JoeSkeen 也许它不起作用,因为 Protractor 运行在全局或本地,您必须根据量角器的执行方式编辑正确的。
  • @BartVerkoeijen Thx,这个提示为我节省了很多调试时间。我仍然很困惑,如果我应该喜欢 JavaScript 中的这种“可扩展性”。
【解决方案2】:

您应该运行 conf.js 文件,而不是 spec.js 文件。

看起来您正在运行命令“protractor spec.js”,而它应该是“protractor conf.js”。错误说它正在寻找一个配置文件,但你正在向它传递一个规范文件。

【讨论】:

  • 当我启动 conf.js 时,它会出现同样的错误,我在更改后的上面的帖子中编辑它
  • 您是否在拥有这些文件的文件夹中运行了“npm install”?
  • 是的,我做了 npm -g install protractor 我什至重新安装了节点并重新安装了一遍,总是同样的错误
【解决方案3】:

将正确的路径传递给 conf.js 文件可能是一种解决方案。尝试导航到您拥有此文件的文件夹,然后再次启动该命令。

当然,指向 conf.js 文件,而不是规范。

【讨论】:

  • 是的,我做了所有它没有工作的一切,我重新安装了所有东西,现在它工作了,所以我把它标记为已解决的 tnx 寻求帮助。不知道是什么问题
【解决方案4】:

我通过重新安装来修复它,不知道问题是如何发生的或者是什么问题

【讨论】:

  • 致反对者:在我的特殊情况下它解决了问题并且在我重新安装节点、量角器和 selenium webdriver 后运行顺利,这怎么不是解决方案。我不知道你希望我做什么,或者你想让我想出一个很好的解决方案@Ddave“这不能解决问题......这不是解决方案。”随意添加解决方案,因为您知道那不是解决方案
  • 需要指出的是,他确实解决了问题。仅仅因为这不是您希望的问题的解决方案并不意味着他们没有通过这样做来解决他们的问题。提出其他建议是完全不正确的。仅仅因为我的车有问题,并不意味着我不能卖掉它来解决我拥有一辆有问题的汽车的问题,这只是意味着汽车的问题并没有消失。开发人员是人,请记住,他们正在寻找解决方案,解决无法正常工作的问题,他们并不是在寻找“无需重新安装即可修复它的方法”。
  • “重新安装应用程序”或“重新启动计算机”绝不是程序员想要的答案。
【解决方案5】:

我遇到了同样的问题(有另一个错误代码),并修复了将 java 路径添加到环境变量(SDK 安装程序没有自动配置它)。

【讨论】:

    【解决方案6】:

    我收到此错误是因为conf.js 的内容无效。
    我错误地使用了seleniumAddress= "http://localhost:4444/wd/hub" 而不是seleniumAddress: "http://localhost:4444/wd/hub"(使用相等的= 而不是冒号:)。

    (错误 105 - conf.js 问题)

    更改conf.js 后,它工作正常,

    exports.config = {
    seleniumAddress: "http://localhost:4444/wd/hub",
    specs: ['spec.js'],
    capabilities:{'browserName': 'chrome'},
    onPrepare(){ 
    browser.driver.manage().window().maximize();
    },
    onComplete(){
    },
    };
    

    【讨论】:

      【解决方案7】:

      我也遇到过同样的问题。但这可能是因为我们没有在 Visual Studio 中保存文件,无论我们编写什么代码,我们都必须保存文件。我保存了它然后运行它,它对我来说很好。对我来说,这就是解决方案。无论我们编写了什么代码,我们都必须在运行之前保存它。

      【讨论】:

      • 欢迎来到 SO!你确定你在回答这个问题吗?用户正在谈论 Angular 之上的 Protactor,而您正在回答有关 Visual Studio...
      • 是的,因为我只在 Visual Studio 中使用量角器。
      【解决方案8】:

      如果你使用它应该可以工作

      exports.config = {
          seleniumAddress: "http://localhost:4444/wd/hub",
          specs: ['spec.js'],
          capabilities:{'browserName': 'chrome'},
          onPrepare(){ 
          browser.driver.manage().window().maximize();
          },
          onComplete(){
          },
      };
      

      但请确保 webdriver-manager 已更新或启动,否则驱动程序连接可能会被拒绝。

      【讨论】:

        【解决方案9】:

        您需要在正确的路径中,然后运行 ​​conf.js protractor conf.js

        【讨论】:

          【解决方案10】:

          我遇到了同样的问题,我用下面的方法来解决。

          exports.config = { 直接连接:真, seleniumAddress: 'http://localhost:4444/wd/hub', 规格:['spec.js'] };

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2017-12-16
            • 1970-01-01
            • 2018-10-02
            • 2019-02-11
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多