Run Codeception Tests in Parallel

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

    git clone https://github.com/browserstack/codeception-browserstack.git
    cd codeception-browserstack
    
  2. Install the dependencies using the following commands:

     composer install
     php composer.phar require codegyre/robo
     php composer.phar require codeception/robo-paracept
    
  3. Setup your credentials and browser/devices where you want to run your test, in the Codeception-BrowserStack/tests/acceptance.suite.yml file as shown below:

     class_name: AcceptanceTester
    
     modules:
       enabled:
         - WebDriver
       config:
         WebDriver:
           host: 'hub-cloud.browserstack.com'
           port: 80
           browser: chrome
           url: 'http://www.google.com'
           capabilities:
             'browserstack.user': 'YOUR_USERNAME'
             'browserstack.key' : 'YOUR_ACCESS_KEY'
    
     env:
       parallel_0:
         modules:
           config:
             WebDriver:
               browser: 'chrome'
    
       parallel_1:
         modules:
           config:
             WebDriver:
               browser: 'firefox'
    
       parallel_2:
         modules:
           config:
             WebDriver:
               browser: 'safari'
    
       parallel_3:
         modules:
           config:
             WebDriver:
               browser: 'internet explorer'
    

    Additionally, you will need the following custom script to launch the tests in parallel (exists in the sample repository).

    Codeception-BrowserStack/RoboFile.php
     <?php
     require_once 'vendor/autoload.php';
     /**
      * This is project's console commands configuration for Robo task runner.
      *
      * @see http://robo.li/
      */
     class Robofile extends \Robo\Tasks
     {
         use \Codeception\Task\MergeReports;
    
         private $numParallel = 4;
    
         public function parallelRun()
         {
             $parallel = $this->taskParallelExec();
             for ($i = 0; $i < $this->numParallel; $i++) {            
                 $parallel->process(
                     $this->taskCodecept() // use built-in Codecept task
                     ->suite('acceptance') // run acceptance tests
                     ->env("parallel_$i")          // in its own environment
                     ->group("single")
                     ->xml("tests/_log/result_$i.xml")
                   );
             }
             return $parallel->run();
         }
    
         function parallelMergeResults()
         {
             $merge = $this->taskMergeXmlReports();
             for ($i=0; $i<$this->numParallel; $i++) {
                 $merge->from("tests/_output/tests/_log/result_$i.xml");
             }
             $merge->into("tests/_output/tests/_log/result.xml")
                 ->run();
         }
    
         function parallelAll()
         {
             $result = $this->parallelRun();
             $this->parallelMergeResults();
             return $result;
         }
     }
     ?>
    
  4. Run your tests in parallel on BrowserStack using following command:

     vendor/bin/robo parallel:all
    
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
Talk to an Expert