Reputation: 801
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?
Upvotes: 7
Views: 10720
Reputation: 18792
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.
Upvotes: 0
Reputation: 11
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
Upvotes: 1
Reputation: 5932
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!
Upvotes: 0
Reputation: 41
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"]
}
}
Upvotes: 4
Reputation: 485
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.
Upvotes: 5