Parallel Test Execution with Protractor


Executing tests in parallel with Protractor in Ranorex Webtestit is very easy. This article explains how to execute all your tests concurrently on the same endpoint and the only thing you need to do is set two following capabilities:

  • shardTestFiles - this is set to false by default and for enabling parallel test execution this must be set to true. When enabled, the specs are split by file and test files are executed in parallel.

  • maxInstances - this setting defines the maximum number of browser instances that are allowed to run concurrently. The default value is 1 and it is only used when shardTestFiles is true. For parallel execution you need to set this value to a number greater than one.

Enable parallel execution for a single endpoint

For all your endpoints you can easily add your own capabilities when creating or editing endpoints. You just need to add shardTestFiles and maxInstances to the capabilities field:
(This can not only be done for local endpoints, but also for remote and custom ones.)

Enable parallel execution for all endpoints

If you have a lot of endpoints, it can be cumbersome to add these capabilities to each endpoint individually. To avoid this, we can also set those capabilities globally, so that they apply for all endpoints.

In order to do that, go to the file protractor.conf.js which can be found on the root level of your project. Here you find the configuration which tells Protractor how to set up Selenium server, which test framework to use, capabilities for certain browser, etc. This file also contains settings for different types of endpoints, e.g. Sauce Labs, Selenium Grid, custom and local endpoints.

Parallel execution on local endpoints
If you want to execute your tests in parallel for all browsers, you just need to add the above mentioned capabilities.

Search in the protractor.conf.js file for the code, where the capabilities are set for local endpoints and after that add shardTestFiles and maxInstances:

  configuration.capabilities = Object.assign({
    browserName: process.env.RX_ENDPOINT_BROWSER,
    operaOptions: {
      args: [],
      extensions: [],
      binary: process.env.RX_OPERA_PATH
  }, capabilities);

  // add the following lines:
  if (process.env.RX_DEBUG !== "true"
    && configuration.capabilities.browserName !== "MicrosoftEdge"
    && configuration.capabilities.browserName !== "safari") {
    configuration.capabilities.shardTestFiles = true;
    configuration.capabilities.maxInstances = 2;

In the above code sample, we excluded Microsoft Edge and Safari from parallel execution, as it is a known issue that Microsoft Edge WebDriver does not support parallel execution and the same applies for the SafariDriver. Furthermore, also running a test in diagnostic mode is not supported and therefore also excluded.

Parallel execution on Sauce Labs, Selenium Grid or custom endpoints
As already mentioned, in protractor.conf.js you can find different settings for different endpoint types. Therefore, in order to enable parallel execution you need to add the capabilities to the according endpoint type.

For example, if you want to enable parallel execution for Selenium Grid endpoints, search in the code for the place where we check the endpoint type: if (process.env.RX_ENDPOINT_TYPE === "seleniumgrid").

Then, just like with local endpoints, add the additional capabilities there:

  let capabilities = Object.assign({
    browserName: process.env.RX_ENDPOINT_BROWSER,
    platform: process.env.RX_ENDPOINT_PLATFORM,
    version: process.env.RX_ENDPOINT_VERSION
  }, customCapabilities);

  // add the following lines:
  if (process.env.RX_DEBUG !== "true"
    && capabilities.browserName !== "MicrosoftEdge"
    && capabilities.browserName !== "safari") {
    capabilities.shardTestFiles = true;
    capabilities.maxInstances = 2;

And as already mentioned above, Edge WebDriver and SafariDriver as well as diagnostic mode do not support parallel execution, and are therefore excluded from parallel execution.

Feature for maximize code window
Code editor should have multiple files in tabs
How to run Typescript tests parallel in Selenium Grid