WebdriverIO - Execute some tests consecutively and other tests in parallel

4.2k Views Asked by At

I have a WDIO project that has many tests. Some tests need to be run consecutively while other tests can run in parallel.

I cannot run all tests in parallel because the tests that need to be run consecutively will fail, and I cannot run all tests consecutively because it would take far too long for the execution to finish.

For these reasons I need to find a way to run these tests both consecutively and in parallel. Is it possible to configure this WDIO project to accomplish this?

I run these tests through SauceLabs and understand that I can set the maxInstances variable to as many VMs as I'd like to run in parallel. Is it possible to set certain tests to use a high maxInstance while other tests have a maxInstance of 1?

Or perhaps there is a way to use logic logic via the test directories to run certain tests in parallel and others consecutively?

For example, if I have these tests:

'./tests/parallel/one.js',
'./tests/parallel/two.js',
'./tests/consecutive/three.js',
'./tests/consecutive/four.js',

Could I create some logic such as:

if(spec.includes('/consecutive/'){
    //Do not run until other '/consecutive/' test finishes execution
} else {
    //Run in parallel
}

How can I configure this WDIO project to run tests both consecutively and in parallel? Thank you!

1

There are 1 best solutions below

5
On

You could create 2 separate conf.js files.

//concurrent.conf.js
exports.config = {
    // ==================
    // Specify Test Files
    // ==================
    specs: [
        './test/concurrent/**/*.js'
    ],
    maxInstances: 1,

and have one for parallel. To reduce duplication, create a shared conf.js and then simply override the appropriate values.

//parallel.conf.js
const {config} = require('./shared.conf');

config.specs = [
        './test/parallel/**/*.js'
    ],
config.maxInstances = 100,

And then when you run your tests you can do:

//parallel
wdio test/configs/parallel.conf.js
//concurrent
wdio test/configs/concurrent.conf.js

Here's an example of how to have a shared config file. And other config files using the shared one