'How can I run Nightwatch tests in a specific order?
I have several tests which test the UI and also serve to create data along the way.
A separate set of tests rely on this data, meaning that these must run only after the first set have run.
I know about running a group of them, or running them with tags, but how can I run them in a specific order?
Solution 1:[1]
This isn't a great answer but it works: numerically sequence your test files.
0001_first_test_I_want_to_run.js
0002_second_test_I_want_to_run.js
...
9999_last_test_I-want_to_run.js
Solution 2:[2]
To control the order (and also to use a common module for authentication) I used a "main" test module and imported the tests in the order I wanted:
Inside main.test.js
// import test modules
const first = require('./first.test.js');
const second = require('./second.test.js');
module.exports = {
before(){
// login, 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 = {
// allow nightwatch to run test module only inside _main
'@disabled': true,
'run': (browser) => {
// call all functions inside tests
Object.values(tests)
.filter(f => typeof f === 'function')
.forEach(f => f(browser));
}
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | QualiT |
| Solution 2 | ow3n |
