ssharma
ssharma

Reputation: 941

Protractor Test Randomly Failing with Error "Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:32572"

My Protractor test randomly fails with error . :

Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:32572 
at ClientRequest.<anonymous> (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\http\index.js:238:15)
    at ClientRequest.emit (events.js:223:5)
    at Socket.socketErrorListener (_http_client.js:406:9)
    at Socket.emit (events.js:223:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
From: Task: WebDriver.navigate().to(data:text/html,<html></html>)
    at Driver.schedule (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\lib\webdriver.js:807:17)
    at Navigation.to (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\lib\webdriver.js:1133:25)
    at Driver.get (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\lib\webdriver.js:988:28)
    at C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\protractor\built\browser.js:675:32
    at ManagedPromise.invokeCallback_ (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\lib\promise.js:1376:14)

Node version : v12.14.1, npm version : 6.13.4, protractor version: 5.4.2, webdriver-manager version: 12.1.6

Note : I am also using async/await in my test.

Upvotes: 0

Views: 619

Answers (2)

Sanja Paskova
Sanja Paskova

Reputation: 1110

This was happening to me when I have more chromedriver.exe processes in background. Terminate all processes in background or restart the computer and you should not see this error.

Upvotes: 1

Sergey Pleshakov
Sergey Pleshakov

Reputation: 8948

There used to be a problem some time ago when this error was specific to a some chromedriver, which had to resolved from selenium side. Since chromedriver 80 is a brand new version, I assume it's just a temporary bug which will be fixed some time soon

Meanwhile, you can try the solution that I used for a while. All you need is just to mute the error, by adding this code before exporting you config file

//////////////////////////////////////////////////////////////////////////////
// temporary work around to avoid 'ECONNREFUSED' error, preferably to find another solution
// remove the block when https://github.com/SeleniumHQ/selenium/pull/5759 will be merged && released

let httpIndexFile = "node_modules/selenium-webdriver/http/index.js";
fs.readFile(httpIndexFile, "utf8", function (err, data) {
    if (err) {
        throw err;
    }

    let result = data.replace(/\(e.code === 'ECONNRESET'\)/g, "(e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED')");
    console.log(`Patching ${httpIndexFile}`);
    fs.writeFileSync(httpIndexFile, result, "utf8");
});

let chromeFile = "node_modules/selenium-webdriver/chrome.js";
fs.readFile(chromeFile, "utf8", function (err, data) {
    if (err) {
        throw err;
    }

    let 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");
});
//////////////////////////////////////////////////////////////////////////////
exports.config = {

Again, this was another problem, but the tweak should work the same

Upvotes: 1

Related Questions