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

Run Tests in Parallel

On BrowserStack, you can run multiple Behat tests at the same time across various browser, device and OS combinations. This is “Parallel Testing”. Parallel Testing gives you the same benefits as running a multi-threaded application helps you reduce the run time of your test suite, resulting in faster build times and faster releases.

To run tests on multiple browsers in parallel with Behat on BrowserStack, modify the config file as shown below:

default:
  paths:
    features: '../features/single'
    bootstrap:  '../features/bootstrap'
  context:
    parameters:
      browserstack:
        server: "hub-cloud.browserstack.com"
        user: "YOUR_USERNAME"
        key: "YOUR_ACCESS_KEY"

        capabilities:
          "browserstack.debug": true

        environments:
          -
            browser: "chrome"
          -
            browser: "firefox"
          -
            browser: "safari"
          -
            browser: "internet explorer"

Capabilities for each environment can be customized as explained earlier.

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

$config_file = getenv('CONFIG_FILE');
if(!$config_file) $config_file = 'config/single.conf.yml';
$CONFIG = Yaml::parse(file_get_contents($config_file))["default"]["context"]["parameters"]["browserstack"];

$procs = array();

foreach ($CONFIG['environments'] as $key => $value) {
    $cmd = "TASK_ID=$key ./bin/behat --config=". getenv("CONFIG_FILE")." 2>&1n";
    print_r($cmd);

    $procs[$key] = popen($cmd, "r");
}

foreach ($procs as $key => $value) {
    while (!feof($value)) {
        print fgets($value, 4096);
    }
    pclose($value);
}

Run your tests in parallel on BrowserStack using following command:

# Run using composer
composer parallel

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 an Expert
Download Copy