Nightwatch: ECONNRESET. Is selenium server started?

Created on 20 Jul 2016  Â·  29Comments  Â·  Source: nightwatchjs/nightwatch

I get this now when try to run Nightwatch. It seemed to begin suddenly and I've got it to run successfully a few times since it started too.

username@hostname ~/D/d/mysite-frontend> npm run e2e

> [email protected] e2e /Users/username/Documents/dev/mysite-frontend
> ./node_modules/nightwatch/bin/nightwatch -c nightwatch.conf.js

Starting selenium server... started - PID:  1376
started - PID:  1376

[Homepage] Test Suite
=========================

Running:  Open login modal

[client :: capabilities] Test Suite
=======================================


Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
{ [Error: socket hang up] code: 'ECONNRESET' }

I've deleted and redownloaded selenium.jar and a few other things, but same error.

needs more info stale

Most helpful comment

Adding "headless" to the chrome args did it for me on our linux ci box.
chromeOptions: { args: [ 'headless', 'no-sandbox'] }

All 29 comments

Can you share the relevant bits of your config?

I didn't set up Nightwatch on the project, but here's the files I guess are relevant.

nightwatch.conf.js

require('babel-core/register');

module.exports = require('./nightwatch.json');

nightwatch.json

{
  "src_folders": ["tests"],
  "output_folder": "reports",
  "custom_commands_path": "",
  "custom_assertions_path": "",
  "page_objects_path": "pages",
  "globals_path": "globals.js",

  "selenium": {
    "start_process": true,
    "server_path": "./bin/selenium.jar",
    "log_path": "./reports",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "./bin/chromedriver"
    }
  },
  "test_settings": {
    "default": {
      "launch_url": "https://localhost:3000",
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "silent": true,
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

Was messing with this issue earlier. Had to set start_process to false and have selenium server running as a background process manually.

Will mention though it worked correctly on one of my macs but not on the other.

Is this still an issue?

Still occurs for me on 0.9.6 when start_process is set to true

Can you run with --verbose and post the output please?

Which OS are you on?

Win 10, I will try to get the output this week

@beatfactor this is still an issue for me on Nightwatch 0.9.7 and after just now reinstalling Selenium as well.

@beatfactor I'm on Mac OS El Capitan. Here is my output with --verbose

npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'run',
npm verb cli   'e2e',
npm verb cli   '--verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'pree2e', 'e2e', 'poste2e' ]
npm info lifecycle  [email protected]~pree2e:  [email protected]
npm info lifecycle  [email protected]~e2e:  [email protected]

>  [email protected] e2e /Users/my-user/Documents/dev/ my-project-frontend
> ./node_modules/nightwatch/bin/nightwatch -c nightwatch.conf.js

Starting selenium server... started - PID:  18895
started - PID:  18895

[Homepage] Test Suite
=========================

Running:  Open login modal

[client :: capabilities] Test Suite
=======================================


Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
{ [Error: socket hang up] code: 'ECONNRESET' }


npm verb lifecycle  [email protected]~e2e: unsafe-perm in lifecycle true
npm verb lifecycle  [email protected]~e2e: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/my-user/Documents/dev/ my-project-frontend/node_modules/.bin:/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
npm verb lifecycle  [email protected]~e2e: CWD: /Users/my-user/Documents/dev/ my-project-frontend
npm info lifecycle  [email protected]~e2e: Failed to exec e2e script
npm verb stack Error:  [email protected] e2e: `./node_modules/nightwatch/bin/nightwatch -c nightwatch.conf.js`
npm verb stack Exit status 1
npm verb stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:239:16)
npm verb stack     at emitTwo (events.js:100:13)
npm verb stack     at EventEmitter.emit (events.js:185:7)
npm verb stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
npm verb stack     at emitTwo (events.js:100:13)
npm verb stack     at ChildProcess.emit (events.js:185:7)
npm verb stack     at maybeClose (internal/child_process.js:850:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
npm verb pkgid  [email protected]
npm verb cwd /Users/my-user/Documents/dev/ my-project-frontend
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "e2e" "--verbose"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.3
npm ERR! code ELIFECYCLE
npm ERR!  [email protected] e2e: `./node_modules/nightwatch/bin/nightwatch -c nightwatch.conf.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the  [email protected] e2e script './node_modules/nightwatch/bin/nightwatch -c nightwatch.conf.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  my-project-frontend package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ./node_modules/nightwatch/bin/nightwatch -c nightwatch.conf.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs  my-project-frontend
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls  my-project-frontend
npm ERR! There is likely additional logging output above.
npm verb exit [ 1, true ]

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/my-user/Documents/dev/ my-project-frontend/npm-debug.log

Can you run (no need to pass -c nightwatch.conf.js, it is automatically picked up):

$ ./node_modules/./bin/nightwatch --verbose

The problem seems to be that Java was not installed (although I do not recall uninstalling it).

brew update
brew cask install java

^ fixed it.

For me all I had to do what change the "webdriver.thing.driver" to have the full file name e.g "./bin/chromedriver.exe"
and then in the "selenium" object set "start_process" : true;

Maybe I'll reopen this so someone can decide whether perhaps a better error message is desired.

I get this error but only when running tests on Jenkins, it never manifests on my local machine. Really tricky to debug since we need to trigger a build each time... basically, output is as follows:

Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
{ Error: socket hang up
    at createHangUpError (_http_client.js:254:15)
    at Socket.socketCloseListener (_http_client.js:286:23)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:498:12) code: 'ECONNRESET' }

I am currently trying to start the selenium server from the bash script which then launches Nightwatch to see if that helps (i.e. disabled starting selenium via nightwatch).

UPDATE: Still getting this using Nightwatch 0.9.12. Followed @jacebenson 's advice and checked my config, but it does point directly to the chromedriver as follows:

    "cli_args" : {
      "webdriver.chrome.driver" : "./node_modules/.bin/chromedriver",
      "webdriver.gecko.driver" : "./node_modules/.bin/geckodriver"
    }

@OKNoah the intermittency of the issue (we also experience it in about 80% of our builds - the others pass fine) is the most confusing part for me. A failed hard dependency such as Java would surely fail each time, and our machines do have java installed so no problem there... kind of wondering how you solved this by updating/installing java haha

So, solved this by adding this process parameter:

DBUS_SESSION_BUS_ADDRESS=/dev/null

See: http://stackoverflow.com/questions/41487659/nightwatch-selenium-socket-hang-up

Got 4 green builds in a row (up from 1 out of 10) - seems like it fixed it.

FWIW I periodically get the same error reported above.

[0;31mConnection refused! Is selenium server started?
[0m[0;90m{ Error: socket hang up
    at createHangUpError (_http_client.js:253:15)
    at Socket.socketCloseListener (_http_client.js:285:23)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:501:12) code: 'ECONNRESET' }[0m

I had this issue before and the solution above for adding the process parameter was working until Nightwatch 0.9.14 was released. Perhaps it's a coincidence, but it was at that time - about 2 weeks ago - that this problem resurfaced.

I got the same error reported above.

1) Scenario: Searching Google - features/main-page.feature:3
   Step: Given I open Google`s search page - features/main-page.feature:5
   Step Definition: features/step_definitions/main-page.js:6
   Message:
     Error: { message: 'Connection refused! Is selenium server started?\n',
       data: 
        { Error: connect ECONNREFUSED 127.0.0.1:4444
            at Object.exports._errnoException (util.js:1034:11)
            at exports._exceptionWithHostPort (util.js:1057:20)
            at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1096:14)
          code: 'ECONNREFUSED',
          errno: 'ECONNREFUSED',
          syscall: 'connect',
          address: '127.0.0.1',
          port: 4444 } }

My error was solved by removing node_modules and running yarn install again. Crazy...But i'll take it

Feature: Google Search

  Scenario: Searching Google
  ✔ Given I open Google`s search page
  ✔ Then the title is "Google"
  ✔ And the Google search form exists

1 scenario (1 passed)
3 steps (3 passed)
0m04.154s

I solved it by reinstalling the chrome driver:
npm i chromedriver --save

Probably kind of unrelated, but maybe useful for the next poor guy: I had this exact issue when trying to run the nightwatch binary from inside a pytest function in Python. This worked great locally, but failed within a tox execution context on Jenkins. What helped in my case was to make sure all environment variables are passed to tox by adding the passenv = * config option inside the tox.ini.

Adding "headless" to the chrome args did it for me on our linux ci box.
chromeOptions: { args: [ 'headless', 'no-sandbox'] }

Have the same error. @beatfactor this is what i have with --verbose

Running: demo test google
INFO Request: POST /wd/hub/session

  • data: {"desiredCapabilities":{"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform":"ANY","marionette":true,"name":"Googletests"}}
  • headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":151}
    ERROR Response 500 POST /wd/hub/session (20438ms) { value:
    { message: 'Timed out waiting for driver server to start.\nBuild info: version: \'3.8.1\', revision: \'6e95a6684b\', time: \'2017-12-01T19:05:32.194Z\'\nSystem info: host: \'WKS036\', ip: \'192.168.10.61\', os.name: \'Windows 10\', os.arch: \'amd64\', o
    s.version: \'10.0\', java.version: \'1.8.0_92\'\nDriver info: driver.version: unknown',
    error: 'unknown error' },
    status: 13 }

Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?

in which file I have to add process parameter "DBUS_SESSION_BUS_ADDRESS=/dev/null", can u please share me the file ?
I am getting below issue while running automation by Jenkins.

[1;35mStarting selenium server... started - PID:  9093
{ Error: Uncaught, unspecified "error" event. ([object Object])
at ClientManager.emit (events.js:163:17)
at Nightwatch. (/home/jenkinsslave/workspace/SC-DEV4/node_modules/nightwatch/lib/runner/clientmanager.js:68:10)
at Nightwatch.g (events.js:291:16)
at emitOne (events.js:96:13)
at Nightwatch.emit (events.js:188:7)
at HttpRequest. (/home/jenkinsslave/workspace/SC-DEV4/node_modules/nightwatch/lib/index.js:501:10)
at emitThree (events.js:116:13)
at HttpRequest.emit (events.js:194:7)
at IncomingMessage. (/home/jenkinsslave/workspace/SC-DEV4/node_modules/nightwatch/lib/http/request.js:172:16)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
context:
{ message: 'Connection refused! Is selenium server started?\n',
data: { value: [Object], status: 13 } } }

Nighwatch file-
const seleniumServer = require('selenium-server');
const phantomjs = require('phantomjs-prebuilt');
const chromedriver = require('chromedriver');
const geckodriver = require('geckodriver');

require('nightwatch-cucumber')({
cucumberArgs: ['--require', 'test/EndtoEnd/step_definitions', '--format', 'json:reports/cucumber.json', 'test/EndtoEnd/features']
});

module.exports = {
output_folder: 'reports',
custom_assertions_path: '',
page_objects_path : 'test/EndtoEnd/page_objects',
live_output: false,
disable_colors: false,
selenium: {
start_process: true,
server_path: seleniumServer.path,
log_path: '',
host: '127.0.0.1',
port: 4444
},
test_settings: {
default: {
launch_url: 'http://localhost:8087',
selenium_port: 4444,
selenium_host: '127.0.0.1',
desiredCapabilities: {
//browserName: 'phantomjs',
javascriptEnabled: true,
acceptSslCerts: true,
//'phantomjs.binary.path': phantomjs.path
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,

    chromeOptions: {
      args: ['use-fake-ui-for-media-stream', '--load-extension=test/EndtoEnd/Plugins/1.2.2_0',
        '--auto-select-desktop-capture-source=Screen 2'],
    }

  },
  selenium: {
    cli_args: {
      'webdriver.chrome.driver': chromedriver.path
    }
  }
},
headless: {
  desiredCapabilities: {
    browserName: 'chrome',
    javascriptEnabled: true,
    acceptSslCerts: true,


    chromeOptions: {
      args: ['use-fake-ui-for-media-stream', '--headless', '--no-sandbox', 'disable-gpu']
    }

  },
  selenium: {
    cli_args: {
      'webdriver.chrome.driver': chromedriver.path
    }
  }
},
firefox: {
  desiredCapabilities: {
    browserName: 'firefox',
    javascriptEnabled: true,
    marionette: true
  },
  selenium: {
    cli_args: {
      'webdriver.gecko.driver': geckodriver.path
    }
  }
},

}
};

None of the above solutions worked for me.
Updating my host file entry fixed this problem.
Fix:
delete all your host file entries and add below entry to your host file.
127.0.0.1 localhost

@OKNoah could you close this? The error message is not coming from nightwatch but selenium.

I had the same issue, and it turned out that I had pointed 127.0.0.1 over to a different domain than localhost :)

I'm still having this problem, showing error messages as the following:
{ state: 'unknown error', sessionId: null, hCode: 27717923, value: { localizedMessage: null, cause: null, suppressed: [], message: null, hCode: 1055615, class: 'java.util.concurrent.TimeoutException', screen: null }, class: 'org.openqa.selenium.remote.Response', status: 13 }

using verbose there's an additional error message: ERROR Response 500 POST /wd/hub/session (20461ms) When I ping the IP it was successful, yet I'm not sure why it seems like redirecting to a new session.

OS is Win7, launched in git bash terminal..

Could anyone help?Thank you!

This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

betweenbrain picture betweenbrain  Â·  4Comments

Pieras2 picture Pieras2  Â·  3Comments

dakebl picture dakebl  Â·  4Comments

lgaticaq picture lgaticaq  Â·  3Comments

Zechtitus picture Zechtitus  Â·  4Comments