handling the 'Connection refused! Is selenium server started?' error

284 views
Skip to first unread message

David Laidlaw

unread,
Sep 21, 2017, 1:15:05 PM9/21/17
to NightwatchJs
The error itself happens sometimes when the chrome containers we have on our grid go down - rare but it happens. That problem I can remedy - the annoyance is that I am unable to catch the error in any of the hooks and deal with it (possibly assert.fail that the selenium server is down). 

I can see nightwatch get into the global beforeEach hook, and in here I can tell it fails. To mimic the problem I was setting my connection to the hub to a false port in the config like so (should be 4444)
selenium_port: 4445,

here is a snippet of what I was trying in the globals.js for the beforeEach hook
beforeEach: (browser, cb) => {
console.log('beforeEach (global)');
const error = 'error UNCAUGHT EXCEPTION';

// add this handler before emitting any events
process.on('uncaughtException', (err) => {
console.log(error, err);
cb(new Error(error));
});
process.on('error', (err) => {
console.log(error, err);
cb(new Error(error));
});
process.on('unhandledRejection', (err) => {
console.log(error, err);
cb(new Error(error));
});
browser.perform(() => {
console.log('here');
cb();
});

and the results in console.
Started child process for: smoketest/someTest
smoketest/someTest [SomeTest] Test Suite
==================================
smoketest/someTest beforeEach (global)
smoketest/someTest Error retrieving a new session from the selenium server
smoketest/someTest
smoketest/someTest Connection refused! Is selenium server started?

smoketest/someTest { Error: connect ECONNREFUSED 172.18.0.2:4445
at Object.exports._errnoException (util.js:1036:11)
at exports._exceptionWithHostPort (util.js:1059:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '172.18.0.2',
port: 4445 }

I am interesting if anyone has managed to handle this error?


Reply all
Reply to author
Forward
0 new messages