question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Moving to async/await while keeping filter raises 'Connection refused: connect' and 'ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444'

See original GitHub issue

Bug report

  • Node Version: v8.5.0
  • Protractor Version: 5.1.0
  • Angular Version: 1.6.7
  • Browser(s): Chrome 64.0.3282.140
  • Operating System and Version Windows 7

While trying to move away from the promise manager of Selenium, I encountered new random failures which were not occurring before. After analyze it appeared that it might be linked to the filter function offered by Protractor.

Here is an extract of the configuration and scripts I am using. All the code is available on https://github.com/dubzzz/protractor-move-async-await. The localhost:3000 exposes the todolist example of AngularJS official website with a list of a thousand entries.

Using the promise manager:

conf.js

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js'],
  SELENIUM_PROMISE_MANAGER: 1
};

todo-spec.js

browser.get('http://localhost:3000/index.html');
element.all(by.repeater('todo in todoList.todos'))
  .filter(todo => todo.getText().then(label => label.indexOf('#10') !== -1))
  .each(todo => todo.element(by.css('input')).click());

Using async/await:

conf.js

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js'],
  SELENIUM_PROMISE_MANAGER: 0
};

todo-spec.js

await browser.get('http://localhost:3000/index.html');
await element(by.model('todoList.todoText')).sendKeys('write first protractor test');
await element(by.css('[value="add"]')).click();
await element.all(by.repeater('todo in todoList.todos'))
  .filter(todo => todo.getText().then(label => label.indexOf('#10') !== -1))
  .each(todo => todo.element(by.css('input')).click());

The asynchronous version failed with the following error:

1) [async] angularjs homepage todo list should add a todo
  Message:
    Failed: java.net.ConnectException: Connection refused: connect

The full proof off concept is available on my personal Github at https://github.com/dubzzz/protractor-move-async-await

Is the bug coming from an issue in my configuration or is there a real issue?

Thanks in advance

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:7
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
CrispusDHcommented, Mar 4, 2018

You could override filter function to force send requests sequential.

 private makeFnSequential(func: any): any {
    let promise: any = Promise.resolve();

    return (...args) => {
      promise = promise.then(() => {
        return func(...args);
      });

      return promise;
    };
  }
}

use this method to wrap filterFn.

Second option is to run your tests directly on chrome (add to config directConnect: true). In that way selenium server will not use at all, so any java errors 😃

5reactions
awarecancommented, May 30, 2018

Also you can try my another patch for chromeDriver persistence connection issue. I don’t have problem for a while after apply both patch

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');
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ECONNREFUSED – connection refused by server ...
If you come across the ECONNREFUSED – connection refused by a server ... Connect to FileZilla FTP client and head to Edit ->...
Read more >
AXIOS request: "Error: connect ECONNREFUSED 127.0.0.1:80"
I set this up on the backend using node.js. I first thought I was using the wrong .env, url, username, and password... but...
Read more >
Connect ECONNREFUSED 127.0.0.1:80 - Node
it was the index folder I have just named it app. However, I have figured out where the error was it just a...
Read more >
How to use promises - Learn web development | MDN
Promises are the foundation of asynchronous programming in modern JavaScript. A promise is an object returned by an asynchronous function, ...
Read more >
connect ECONNREFUSED 127.0.0.1:3306 solved in Node JS ...
How to fix Error: connect ECONNREFUSED 127.0.0.1:3306 in node js and mysql is shown.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found