TL;DR: Before running a test suite, I need to execute code that depends on which specific test suite is going to run, such as logging in as a particular user.
In my wdio.conf.js
file, the relevant section looks like this:
exports.config = {
specs: [
'./spec/**/*.spec.js'
],
suites: {
allExceptAandB: [
'./spec/**/!(A|B).spec.js'
],
A: [
'./spec/A.spec.js'
],
B: [
'./spec/B.spec.js'
]
},
[...]
}
When using the command line argument --suite A
, only the A.spec.js
will be executed, which is the expected behavior.
Now, I want to run some initialization code before each test suite based on which suite is being run, such as calling login(usernameA, passwordA)
or login(usernameB, passwordB)
.
If I use
before: function(capabilities, specs) {
login(username, password)
}
in my wdio.conf.js
, this code seems to be executed before every single spec. Additionally, when using
beforeSuite: function(suite) {
console.log(suite)
}
I noticed that it was also executed before every spec and displayed the suite information.
My expectation is that
before
should run before any test suite beginsbeforeSuite
should run before each suite, and there should be a way to access the name of the suite being executed in order to adjust parameters for tasks like logging in
How can I achieve this functionality?