Note that the error "ECONNREFUSED ::1:4723" complains about "::1" address which is a loopback address for IPv6.
I've got a similar problem after upgrading to Node 18 (from Node 16) on CircleCI.
In my case, the error looked like this:
Unable to connect to “http://localhost:4723/”, make sure browser driver is running on that address.
..
ERROR webdriver: RequestError: connect ECONNREFUSED ::1:4723
The localhost
resolves to IPv6 address ::1
and the connection fails as the server (Appium) only runs on IPv4 address (127.0.0.1
).
The problem is caused by the change in Node’s DNS lookup procedure and starting with Node 17, it does not resolve localhost to 127.0.0.1 (IPv4 address) by default (instead it got resolved to IPv6 ::1 address which caused connection error):
Node.js no longer re-sorts results of IP address lookups and returns them as-is (i.e. it no longer ignores how your OS has been configured)
Discussion is here: https://github.com/nodejs/node/issues/40702.
In the case of native webdriver.io tests, it both starts the server (Appium) and acts as a client, trying to connect to it via http://localhost:4723
.
I found a configuration option to change the port, but I didn’t find a way to configure Appium server address (to change
localhost
to 127.0.0.1
). As a simpler solution, I switched to Node 20 before running tests:
nvm install 20
nvm use 20
cd e2e-webdriver
npm run test:ios
This way tests run with Node 20 that has a fall-back to IPv4 and the connection works.