nightwatch connection refused to selenium server: how to fix
Fixes Nightwatch 'connection refused' to the Selenium server. Use when Nightwatch cannot reach the server. Not for test assertion failures.
TL;DR
Nightwatch talks to a Selenium server that is not running. Start the server (or use direct driver mode), match the host and port in config, and verify with curl.
Error
Error: Connection refused to selenium server at YOUR_HOST:4444Steps
- Check if anything listens:
curl YOUR_HOST/status. Expected: 200 means it is up and the config is wrong. - Start the server:
java -jar selenium-server.jar standaloneor let Nightwatch manage it. Expected: the status endpoint responds. - Match
selenium.hostandselenium.portin nightwatch.conf.js to reality. Expected: config equals the server. - Consider direct driver mode (
webdriverwith chromedriver) to skip the server entirely. Expected: simpler setup, fewer moving parts. - Re-run. Expected: Nightwatch connects.
When to use
Connection refusedto the Selenium server at startup.- Server-based (not direct) setups.
When not to use
- Assertion failures in running tests.
- Direct driver mode issues.
Tool compatibility
- Nightwatch 2.x/3.x; Selenium server 4.x.
Variant phrasings
Nightwatch ECONNREFUSED the loopback address:4444
The same failure in Node terms.
Selenium server not running for Nightwatch
Start it or switch to direct mode.
Why it happens
Nightwatch is a client; without a server there is nothing to talk to. Config drift between the two is the usual cause.
Edge cases
- Java version matters for the server jar; check compatibility.
- Grid URLs differ from standalone; use the right path.
- Direct mode removes the server but needs the driver binary managed.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_VBfjFxOPM0A-IEO3FBvgxw
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.