Organizing Test Suite
As projects grow, inevitably more and more integration tests are added. This increases build time and slows productivity.
To prevent this, you should run your tests in parallel. WebdriverIO already tests each spec (or feature file in Cucumber) in parallel within a single session. In general, try to test only a single feature per spec file. Try to not have too many or too few tests in one file. (However, there is no golden rule here.)
Once your tests have several spec files, you should start running your tests concurrently. To do so, adjust the maxInstances
property in your config file. WebdriverIO allows you to run your tests with maximum concurrency—meaning that no matter how many files and tests you have, they can all run in parallel. (This is still subject to certain limits, like your computer’s CPU, concurrency restrictions, etc.)
Let's say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have set
maxInstances
to1
. The WDIO test runner will spawn 3 processes. Therefore, if you have 10 spec files and you setmaxInstances
to10
, all spec files will be tested simultaneously, and 30 processes will be spawned.
You can define the maxInstances
property globally to set the attribute for all browsers.
If you run your own WebDriver grid, you may (for example) have more capacity for one browser than another. In that case, you can limit the maxInstances
in your capability object:
// wdio.conf.js
export const config = {
// ...
// set maxInstance for all browser
maxInstances: 10,
// ...
capabilities: [{
browserName: 'firefox'
}, {
// maxInstances can get overwritten per capability. So if you have an in-house WebDriver
// grid with only 5 firefox instance available you can make sure that not more than
// 5 instance gets started at a time.
browserName: 'chrome'
}],
// ...
}
Inherit From Main Config File
If you run your test suite in multiple environments (e.g., dev and integration) it may help to use multiple configuration files to keep things manageable.
Similar to the page object concept, the first thing you’ll need is a main config file. It contains all configurations you share across environments.
Then create another config file for each environment, and supplement the the main config with the environment-specific ones:
// wdio.dev.config.js
import { deepmerge } from 'deepmerge-ts'
import wdioConf from './wdio.conf.js'
// have main config file as default but overwrite environment specific information
export const config = deepmerge(wdioConf.config, {
capabilities: [
// more caps defined here
// ...
],
// run tests on sauce instead locally
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
services: ['sauce']
}, { clone: false })
// add an additional reporter
config.reporters.push('allure')
Grouping Test Specs In Suites
You can group test specs in suites and run single specific suites instead of all of them.
First, define your suites in your WDIO config:
// wdio.conf.js
export const config = {
// define all tests
specs: ['./test/specs/**/*.spec.js'],
// ...
// define specific suites
suites: {
login: [
'./test/specs/login.success.spec.js',
'./test/specs/login.failure.spec.js'
],
otherFeature: [
// ...
]
},
// ...
}
Now, if you want to only run a single suite, you can pass the suite name as a CLI argument:
wdio wdio.conf.js --suite login
Or, run multiple suites at once:
wdio wdio.conf.js --suite login --suite otherFeature