Skip to main content
Introducing the Automate SDK! Get your entire test suite running on BrowserStack in minutes! Learn More.

Run Protractor Tests in Parallel

A guide to running multiple Protractor tests in parallel

On BrowserStack, you can run multiple Protractor 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 protractor-browserstack sample repo on GitHub, if not already done:

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

    parallel.conf.js
    exports.config = {
      'specs': [ '../specs/single.js' ],
      'browserstackUser': 'YOUR_USERNAME',
      'browserstackKey': 'YOUR_ACCESS_KEY',
    
      // These capabilities would apply to all the combinations where the tests run in parallel
      'commonCapabilities': {
        'build': 'protractor-browserstack',
        'name': 'parallel_test',
        'browserstack.debug': 'true',
        'browserName': 'Chrome'
      },
    
      maxSessions: 5, // You can change this to the maximum parallel limit for your BrowserStack account
    
      // Every platform specific capability must be defined here. This example shows 4 desktop browsers where the tests would run
      'multiCapabilities': [{
        'browserName': 'Chrome'
      },{
        'browserName': 'Safari'
      },{
        'browserName': 'Firefox'
      },{
        'browserName': 'IE'
      }],
    
      // Code to mark the status of test on BrowserStack based on test assertions
      onComplete: function (passed) {
        if (!passed) {
          browser.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "At least 1 assertion has failed"}}');
        }
        if (passed) {
          browser.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "All assertions passed"}}');
        }
      }
    };
    
    // Code to support common capabilities
    exports.config.multiCapabilities.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/protractor conf/parallel.conf.js
    
  5. You can also run you test in other environments by specifying that in the multiCapabilities variable as shown below:
    "multiCapabilities": [{
         "browser": "chrome",
         "browser_version": "latest",
         "os": "Windows",
         "os_version": "10"
       },{
         "device": "iPhone 12 Pro",
         "browser": "iPhone",
         "os_version": "14"
       },{
         "browser": "safari",
         "browser_version": "latest",
         "os": "OS X",
         "os_version": "Big Sur"
       },{
         "device": "Samsung Galaxy S20 Ultra",
         "browser": "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 which must be defined in the 'browserstackUser' and 'browserstackKey' variable in Protractor)

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

Queuing

With queuing, you can launch an additional number of parallel tests with different browser configurations that will be queued in a sequence. For instance, if you want to run 5 additional tests, apart from your subscribed limit of 2 parallel tests, BrowserStack will queue the additional 5 tests until one of the 2 initial tests finish, and a slot is available for execution. With queuing, you don’t need to worry about managing your test pipeline - we automatically take care of scheduling and execution for you.

With this feature, accounts up to 5 parallel tests can queue 5 tests. Beyond 5 parallel tests, an equivalent number of tests will be queued.

Protip: You can define maxSessions: n in the *.conf.js file and Protractor would create a maximum of n sessions at a time.

Next steps

Once you have successfully run your first test on BrowserStack, you might want to explore the following:

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 an Expert
Talk to an Expert