Skip to main content

Get Started with Parallel Testing

On BrowserStack, you can run the same test simulatenously on different device and OS version combinations, or run different tests simultaneously on the same device and OS version combination. This is called Parallel Testing. Parallel Testing will help you reduce the run time of your test suite, resulting in faster build times and faster releases.

For example, if your test suite takes 30 minutes to execute sequentially, running it with 10 parallel tests might cut down the test execution time to be as low as 3 minutes (of course, this is based on the assumption that all your test cases take more or less the same time).

Note: Your App Automate plan needs to have sufficient licenses to be able to run parallel tests. If you trigger more tests than what you subscribed for, they will either be queued or discarded.

Example:

To run tests on multiple devices in parallel on BrowserStack, modify the config file as below:

Note: Remember to update the app capability with the app_url (bs://hashed-id) obtained after uploading app on BrowserStack

{
  "server": "hub-cloud.browserstack.com",
  "user": "YOUR_USERNAME",
  "key": "YOUR_ACCESS_KEY",

  "capabilities": {
    "project": "PHPUnit_AppAutomate",
    "build": "phpunit-app_automate-browserstack",
    "name": "android_parallel",
    "browserstack.debug": true,
    "app":"your_app_url"
  },
  "devices": [{
    "device": "Samsung Galaxy S8",
    "device": "Samsung Galaxy S8 Plus"
  }]
}
{
  "server": "hub-cloud.browserstack.com",
  "user": "YOUR_USERNAME",
  "key": "YOUR_ACCESS_KEY",

  "capabilities": {
    "project": "PHPUnit_AppAutomate",
    "build": "phpunit-app_automate-browserstack",
    "name": "android_parallel",
    "browserstack.debug": true,
    "app":"your_app_url"
  },
  "devices": [{
    "device": "iPhone 7",
    "device": "iPhone 7 Plus"
  }]
}

You need the following custom script to launch the tests in parallel.

<?php
$run_cmd = "composer android_parallel"; // for ios "composer ios_parallel"
$num_of_tests = 2;
$procs = array();
for($x = 0; $x < $num_of_tests; $x++) {
  putenv("TASK_ID=$x");
  $procs[$x] = popen($run_cmd, "r");
}
for($x = 0; $x < $num_of_tests; $x++) {
  while (!feof($procs[$x])) {
        print fgets($procs[$x], 4096);
  }
  pclose($procs[$x]);
}
?>

Run your tests in parallel on BrowserStack using following command:

# Run using composer
composer parallel
Note: Refer to our GitHub repository for a complete example: BrowserStack - PHPUnit

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