Nightwatch Selenium "socket hang up"
Asked Answered
B

5

7

Running Nightwatch tests on CI in Chrome. Sometimes (about once in 5 builds) I encounter following error, in one of the tests. Every test before this one works fine.

I have the latest Chromedriver and Selenium standalone server.

I figured that the problem is that Selenium server crashes mid-request, tough I don't know why.

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' }

Also here is part of my nightwatch.json that takes care of selenium.

 "selenium": {
    "start_process": true,
    "server_path": "scripts/Nightwatch/selenium-server-standalone-3.0.1.jar",
    "log_path": "app/E2E/reports/selenium",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "scripts/Nightwatch/chromedriver"
    }
  }

Any ideas why is Selenium crashing and how to fix this issue?

Blackberry answered 5/1, 2017 at 14:35 Comment(0)
D
5

Had the exact same issue with selenium/chromedriver on Codeship. I tried downgrading selenium to 2.53.1 to no avail. Verbose logging showed no helpful info, just the selenium server suddenly not starting new sessions somewhere randomly in our tests.

What appeared to work was adding the following to our test commands:

# Prevent chrome deadlock
export DBUS_SESSION_BUS_ADDRESS=/dev/null

Issue is described here: https://github.com/SeleniumHQ/docker-selenium/issues/87

It looks like there is an issue with certain docker containers which would explain it happening on a CI while locally working just fine.

Degraw answered 13/1, 2017 at 9:2 Comment(4)
I still had the problem after doing this but then realized i did not run xvfb-run around the command for headless testing xvfb-run npm run e2e working nowMarras
@MartinNaughton Would you mind turning this into an answer? It fixed the problem for me.Aright
What on earth is e2e :D?Ias
e2e == "end to end"... another name for browser automation testsAndrien
G
4

The same exception message is displayed (every time a build is run) when chrome is not configured correctly in nightwatch.json. Specifically it requires the "--no-sandbox" option to be provided e.g

"chrome": {
  "desiredCapabilities": {
  "browserName": "chrome",
  "javascriptEnabled": true,
  "acceptSslCerts": true,
  "chromeOptions": {
    "args" : ["--no-sandbox"]
  }
}
Gelatin answered 28/6, 2017 at 11:45 Comment(0)
D
1

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

Deka answered 1/2, 2018 at 21:20 Comment(0)
B
0

I used the following args notation, got Connection refused and used xvfb as a workaround.

chrome: {
  silent: false,
  retry_attempts: 1,
  desiredCapabilities: {
    browserName: 'chrome',
    javascriptEnabled: true,
    acceptSslCerts: true,
    chromeOptions: {
      args: [
        '--disable-gpu --no-sandbox --headless --window-size=1920,1080 --verbose'
      ]
    }
  }
},

Now a colleague found out that the args should be separate and without dashes:

      args: [
        'disable-gpu', 'no-sandbox', 'headless', 'window-size=1920,1080', 'verbose'
      ]

No more errors even without xvfb - works for me!

Belshazzar answered 7/1, 2018 at 20:38 Comment(0)
M
0

I was getting the following error when running Nightwatch:

Error: An error occurred while retrieving a new session: "session not created" at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

Checking the Task Manager there were 100s of Google Chrome processing running and the CPU was at 99%. I'm not sure what caused this issue but restarting the server removed the processes and allowed Nightwatch to function again.

Measly answered 15/9, 2021 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.