【问题标题】:Random occurrences of Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1 when running protractor tests运行量角器测试时随机出现 Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1
【发布时间】:2018-11-07 20:19:58
【问题描述】:

我的量角器测试用例随机失败并显示以下错误消息:

失败:ECONNREFUSED 连接 ECONNREFUSED 127.0.0.1

我浏览了资源并尝试了所有建议的解决方案:

  • 升级量角器
  • 运行 webdriver-manager 更新
  • 已升级 chromedriver 版本,但问题似乎存在。

当我尝试同时运行所有 e2e 测试时,尤其会发生这种情况。

以下是我用于我的项目的特定版本:

  • 节点 - v9.2.0
  • 量角器 - 版本 5.4.1
  • ChromeDriver 2.42.591088

请帮忙。

谢谢, 尼拉哈

【问题讨论】:

  • 是的,下面的答案对我有用

标签: node.js protractor


【解决方案1】:

您是否在测试中使用 async/await?

您可以尝试通过执行“node patch.js”从包含“node_modules”文件夹的同一文件夹中应用下面指定的补丁吗?

patch.js 文件

var fs = require('fs');
var httpIndexFile = 'node_modules/selenium-webdriver/http/index.js';
fs.readFile(httpIndexFile, 'utf8', function (err, data) {
if (err)
    throw err;
var result = data.replace(/\(e.code === 'ECONNRESET'\)/g, "(e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED')");
console.log(`Patching ${httpIndexFile}`)
fs.writeFileSync(httpIndexFile, result, 'utf8');});
var chromeFile = 'node_modules/selenium-webdriver/chrome.js';
fs.readFile(chromeFile, 'utf8', function (err, data) {
if (err)
    throw err;

var result = data.replace(/new http.HttpClient\(url\)/g, "new http.HttpClient(url, new (require('http').Agent)({ keepAlive: true }))");
console.log(`Patching ${chromeFile}`)
fs.writeFileSync(chromeFile, result, 'utf8');});

请在此处查看原始帖子- https://github.com/angular/protractor/issues/4706#issuecomment-393004887

【讨论】:

  • 是的,我在测试中使用 async/await。将尝试这种解决方法,看看,非常感谢:) !!
猜你喜欢
  • 2023-04-10
  • 2013-12-02
  • 2022-11-23
  • 1970-01-01
  • 2020-11-20
  • 2021-02-24
  • 2020-02-02
  • 1970-01-01
  • 2023-02-16
相关资源
最近更新 更多