Unable to run Protractor - ECONNREFUSED connect ECONNREFUSED

房东的猫 提交于 2019-11-28 04:54:18

I solved this with --standalone flag:

webdriver-manager start --standalone

I got it working by removing the following line from my config.js

seleniumAddress: 'http://localhost:4444/wd/hub',

Are you running a selenium server? The git README states the following:

WebdriverJS does not natively include the selenium server - you must start a standalone selenium server. All you need is the latest selenium-server-standalone.

source: https://github.com/angular/protractor

The error message is due to the following:

[ECONNREFUSED] The attempt to connect was ignored (because the target is not listening for connections) or explicitly rejected.

Check the URL of the Webdriver manager. The default URL is:

http://localhost:4444/wd/hub

Use a background process to run the webdriver-manager, then run protractor:

Start-Process webdriver-manager start -passthru
protractor conf.js

This will start up a Selenium Server and will output a bunch of info logs. Your Protractor test will send requests to this server to control a local browser. Leave this server running

References

Shardul

For me, this had happened due to incompatible versions of Node and Protractor.

My fix-

  1. Update Node to latest version (v7.0.0 in my case)

Follow steps given here https://stackoverflow.com/a/19333717/1902831

  1. Install latest protractor version (4.0.10 in my case) using:

npm install -g protractor

  1. Open another terminal and execute these command:

webdriver-manager update

webdriver-manager start

  1. Run tests in another terminal using:

protractor conf.js

If you are using the npm protractor-webdriver grunt plugin (https://www.npmjs.org/package/grunt-protractor-webdriver) you may exeprience same kind of error. This is due to webdriver termination just before test ends. The test runs successfully and then you have a message like :

Session deleted: Going to shut down the Selenium server
Shutting down Selenium server: http://127.0.0.1:4444
Shut down Selenium server: http://127.0.0.1:4444 (OKOK)

d:\Projets\Clouderial\nodeProjects\cld-apps\node_modules\grunt-protractor-runner\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:145
      callback(new Error(message));
               ^
Error: ECONNREFUSED connect ECONNREFUSED
    at ClientRequest.<anonymous> (d:\Projets\Clouderial\nodeProjects\cld-apps\node_modules\grunt-protractor-runner\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:145:16)
    at ClientRequest.EventEmitter.emit (events.js:95:17)
    at Socket.socketErrorListener (http.js:1547:9)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:440:14
    at process._tickCallback (node.js:419:13)

I resolve this using the keepAlive option in the grunt plugin.

Here is my Gruntfile.js config :

protractor_webdriver: {
        options: {
            keepAlive : true   // True to keep the webdriver alive
        },
        start: {
        },
    },
...

I hope this will help someone.

JM.

I also faced the same problem,the trick that worked for me is to use two cmd windows,keeping the one open after typing webdriver-manager start and without pressing enter key(if enter key is pressed the selenium server is shutdown,don't know why) open another cmd window and call your tests.

@Alexandros Spyropoulos, it took me quite some time to figure out how to run protractor and I think we had the same problem. You should open one terminal tab and run webdriver-manager start --standalone. Then open another terminal tag and run protractor ***.conf.js

David Remie

In the hopes that it might help someone: I'd been having the same problem - encountering ECONNREFUSED using grunt-protractor-runner. The nuance to my case is that I was running my entire E2E environment (test files, web application and entire backend) within a Docker container.

I tried running protractor

  • with and without additional grunt-protractor-webdriver task to get webdriver up and running 'manually' (no difference);
  • with and without enabling directConnect and keepAlive settings (bypassing Selenium and resulting in crashes related to Chromedriver, one of which was described here).

The solution was rather simple: increase the amount of memory allocated to the container. On my Windows 10 host machine, I performed the following steps:

  1. Run VBoxManage.exe modifyvm default --memory 8192 (via custom shell script) before starting the docker-machine (via Docker Quickstart script, which is equivalent to docker-machine start). (Thanks to this SO answer).
  2. Changing my shell script to run my default container, adding the --shm-size=4G argument to my docker run command. (See docs)
    • You can verify if it worked by running df -h in your guest machine, by checking the amount of memory mounted on /dev/shm.

As a result, I no longer have seemingly inexplicable errors such as ECONNREFUSED.

Vicky Rajkumar

If you run the provided protractor demo, you should try running the protractor config in the same command prompt as selenium. Try running both selenium server and protractor separately.

Make Sure first selenium runs by following command.

webdriver-manager start --standalone

And run the protractor in a separate command window.

protractor conf.js

(In my case conf.js was the config file )

I faced a similar issue to the one @David Remie faced with the Selenium Docker grid/standalone. With minimal RAM/CPU, the tests would start before the webdriver was up. A less resource consuming approach is to wait a few seconds before testing (run 'sleep 5' or something like that).

Increasing RAM was sometimes enough as a workaround for the issue, but the real problem was that the Selenium CMD (/opt/bin/entry_point.sh, starts a supervisor that runs the webdriver) from the image based on https://hub.docker.com/r/selenium/node-base/dockerfile was taking time to start the Selenium webdriver.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!