Run WebdriverIO Tests in Parallel

A guide to running multiple WebdriverIO tests in parallel

On BrowserStack, you can run multiple WebdriverIO tests at the same time across various browser, device and OS combinations. This is called Parallel Testing. Parallel Testing gives you the same benefits as running a multi-threaded application.

With Parallel Testing, you can run the same test on different browser/device combinations i.e. cross-browser testing, or run different tests on the same or different browser/device combinations. Parallel Testing will help you reduce the run time of your test suite, resulting in faster build times and faster releases.

Run sample test in parallel

  1. Clone the webdriverio-browserstack sample repo on GitHub, if not already done:

    git clone https://github.com/browserstack/webdriverio-browserstack
    cd webdriverio-browserstack
    
  2. Install the dependencies using npm install
  3. Setup your credentials and browser/devices where you want to run your test, in the webdriverio-browserstack/conf/parallel.conf.js file as shown below:

    parallel.conf.js
    exports.config = {
      user: 'YOUR_USERNAME',
      key: 'YOUR_ACCESS_KEY',
    
      specs: [
        './tests/specs/single_test.js'  // You can add other test scripts here as a comma separated list
      ],
      maxInstances: 10,  // This defines how many maximum tests would run in parallel
      commonCapabilities: {
        name: 'parallel_test',
        build: 'webdriverio-browserstack'
      },
    
      // All the specs defined above will run across all the combinations listed below
      capabilities: [{
        browserName: 'chrome'
      },{
        browserName: 'firefox'
      },{
        browserName: 'internet explorer'
      },{
        os: 'OS X',
        os_version: 'Catalina',
        browserName: 'safari'   // You can define all other capabilities that you want in your tests, in this section
      }],
    
      logLevel: 'warn',
      coloredLogs: true,
      screenshotPath: './errorShots/',
      baseUrl: '',
      waitforTimeout: 10000,
      connectionRetryTimeout: 90000,
      connectionRetryCount: 3,
      host: 'hub.browserstack.com',
    
      before: function () {
        var chai = require('chai');
        global.expect = chai.expect;
        chai.Should();
      },
      framework: 'mocha',
      mochaOpts: {
          ui: 'bdd'
      },
    
      // Code to mark the status of test on BrowserStack based on the assertion status
      afterTest: function (test, context, { error, result, duration, passed, retries }) {
        if(passed) {
          browser.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Assertions passed"}}');
        } else {
          browser.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "At least 1 assertion failed"}}');
        }
      }
    }
    
    // Code to support common capabilities
    exports.config.capabilities.forEach(function(caps){
      for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i];
    });
    }
    
  4. Run your first test using the following command:
    ./node_modules/.bin/wdio conf/parallel.conf.js
    
  5. You can also run you test in other environments by specifying that in the capabilities variable as shown below:
    "capabilities": [{
         browserName: "chrome",
         browser_version: "latest",
         os: "Windows",
         os_version: "10"
       },{
         device: "iPhone 12 Pro",
         browserName: "iPhone",
         os_version: "14"
       },{
         browserName: "safari",
         browser_version: "latest",
         os: "OS X",
         os_version: "Big Sur"
       },{
         device: "Samsung Galaxy S20 Ultra",
         browserName: "Android",
         os_version: "10.0"
       }]
    
Note:
  • You can run your test on real mobile devices by declaring browserName: 'iPhone' or browserName: 'android'.
  • Test scripts should usually be different for mobile devices because websites render differently in mobile browsers
  • Generate a list of capabilities that you want to use in the capabilities section of parallel.conf.js file. (except the credentials)

You can visit BrowserStack Automate Dashboard and see your test there once it has successfully completed.

Note: Achieve your test coverage and build execution time goals by using our calculator to understand how many parallel sessions you need.

We're sorry to hear that. Please share your feedback so we can do better






Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better






Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to automation expert