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)
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?