To maintain the order of tests and streamline authentication, I devised a method using a "main" test module where I imported the tests in a specific sequence:
Within main.test.js
// importing test modules
const first = require('./first.test.js');
const second = require('./second.test.js');
module.exports = {
before(){
// perform login actions, etc.
},
'first': (browser) => {
first.run(browser);
},
'second': (browser) => {
second.run(browser);
},
}
and in first.test.js
var tests = {
'google': (browser) => {
browser.url('https://google.com';
},
'cnn': (browser) => {
browser.url('https://cnn.com';
}
};
module.exports = {
// prevent nightwatch from running this test module outside _main
'@disabled': true,
'run': (browser) => {
// execute all functions within tests
Object.values(tests)
.filter(f => typeof f === 'function')
.forEach(f => f(browser));
}
};