WebdriverIO - Running Tests in Parallel



We can run WebdriverIO tests in parallel mode. For this we have to create more than one spec file within the test folder. The numbers of threads in which parallel tests can run are defined by the parameters in the Configuration file - wdio.conf.js file.

The details on how to create a Configuration file are discussed in detail in the Chapter - Wdio.conf.js file and Chapter - Configuration File generation to store WebdriverIO settings.

Let us take a project having three spec files within the test folder. The following screen will appear on your computer −

Running Tests

To execute all these files in a parallel mode, we have to first specify './test/specs/**/*.js' under the specs field in the wdio.conf.js file. This means all the spec files within the test folder would get triggered on running the command given below −

npx wdio run wdio.conf.js.

The following screen will appear on your computer −

Running the Command

After the command has been executed successfully, we shall see all the three spec files - testcase1.js, testcase2.js and testcase3.js getting triggered for execution simultaneously.

The following screen will appear on your computer −

Execution Simultaneously

Also, the maxInstances field in the wdio.conf.js determines the maximum number of threads possible to trigger the parallel execution. By default, the value is set to 10. Here, we have three spec files, so the maxInstances = 10, holds true.

The following screen will appear on your computer −

MaxInstances

There is another field called capabilities within the wdio.conf.js file. Within this, we have a parameter called the maxInstances. It determines the number of instances that can be opened simultaneously by the Chrome browser during the parallel run.

Let us set the value 3 for the parameter maxInstances outside the capabilities field and then set the value 2 for the field maxInstances inside the capabilities field. The value set for maxInstances within the capabilities overrides the value set for maxInstances outside the capabilities.

Run the following command −

npx wdio run wdio.conf.js

After the command has been executed successfully, we shall see two spec files - testcase1.js and testcase2.js getting triggered for execution simultaneously in Chrome. They are initially in RUNNING status.

Once the status of testcase2.js moved to PASSED, the third spec testcase3.js moved to the status of RUNNING. The following screen will appear on your computer −

Running Status
Advertisements