Part 9: Parallelization

Now that we have two tests, we can start thinking about parallelizing the test run. WebdriverIO documentation lists some ideas for organizing the test suite to support parallel test execution.

We can adjust the maxInstances property in the config file to achieve this.

In shared config, we currently currently set the value of max instances by getting the value from this method call.

The method itself gets the value from the argument that is passed in the test run command. If there is no argument passed in the test run command, the default value is set to 1.

function getArg(argName: string): string | undefined {
  const args = process.argv;
  return args.find(arg => arg.includes(argName));
}

function getOptionalArgValue(argName: string): string | undefined {
  const arg = getArg(argName);
  if (arg) {
    return arg.split('=')[1];
  }
}

export function getMaxInstances(): number {
  const maxInstances = getOptionalArgValue('max_instances');

  return maxInstances ? Number(maxInstances) : 1;
}

Running web tests in parallel

We can run the web tests in parallel by passing max_instances argument:

npm run test:web:chrome -- --max_instances=2

This will launch two instances of Chrome browser and run the different features in each.

Running android tests in parallel

Similar to the web test run command, we would need to pass max_instances to the android test run command too.

But, for android tests to run in parallel without conflicting with each other, we would need to have as many emulators / devices as the number of parallel instances we want. So, we would need to start another emulator. Also, we would need different mjpeg port for the different instances. These are mentioned in the android specific config.

We can pass the device udids to the test run command and specify the max_instances:

npm run test:app:android -- --app_path=/Users/lavanya/projects/demo/book-info-e2e-tests/resources/book-info.apk --devices='emulator-5554,emulator-5556' --max_instances=2

This will start two parallel test runs if there are two features.

We can clone the search.feature and run the tests. The parallel execution is shown below.