Git Product home page Git Product logo

codeception-browserstack's Introduction

Codeception-BrowserStack

Run Codeception tests on BrowserStack. Sequentially and in parallel.

Setup a sample Codeception test to run on BrowserStack

  1. Add codecept.phar to a sample project folder by excuting the following command: wget http://codeception.com/codecept.phar or curl -O http://codeception.com/codecept.phar

  2. Execute php codecept.phar bootstrap

  3. Execute php codecept.phar generate:cept acceptance Welcome

  4. To configure the test, open and edit ./tests/acceptance.suite.yml and copy the file from Sample Tests/acceptance.suite.yml.

  5. Execute php codecept.phar build.

  6. Lets write a test to search BrowserStack on Google. Open and edit file ./tests/acceptance/WelcomeCept.php and copy the file from Sample Tests/WelcomeCept.php.

  7. To run a single test (on say Firefox), execute the command php codecept.phar run --env firefox.

Sequential Runs

  1. You can make use of Environments, to execute tests on different browser and OS combinations.

  2. Check the acceptance.suite.yml to see how the capabilities and environments are mentioned.

  3. To run sequentially of 4 environments, execute the command php codecept.phar run --env chrome --env firefox --env ie --env safari

Parallel Testing

To run sample test in parallel, you need the following two things:

  • Robo, a task runner that executes your tests in parallel
  • robo-paracept - Codeception tasks for parallel execution.

You can follow these steps:

  1. Install 'Composer' if you haven't yet : curl -sS https://getcomposer.org/installer | php

  2. Add the composer.json file present under Parallel Testing folder to the root directory of the project.

  3. Execute the command php composer.phar install to install the two components mentioned above.

  4. Execute Robo.phar and press 'Y' to create an empty RoboFile.php.

  5. Copy the RoboFile.php file under Parallel Testing to the empty RoboFile.php.

  6. Change the env names to p1, p2... instead of chrome, firefox..., as given in acceptance.suite.yml file in Parallel testing folder

  7. The following function in RoboFile executes tests in parallel:

public function parallelRun()
    {
        $parallel = $this->taskParallelExec();
        for ($i = 1; $i <= 4; $i++) {            
            $parallel->process(
                $this->taskCodecept() // use built-in Codecept task
                ->suite('acceptance') // run acceptance tests
                ->env("p$i")          // in its own environment
                ->xml("tests/_log/result_$i.xml") 
              );
        }
        return $parallel->run();
    }

Execute the commmand robo.phar parallel:run to execute tests in parallel.

It would be very confusing to have logs of multiple tests coming at once. Hence it is necessary to merge them. This is where robo-paracept's MergeReports comes into play which merges all results into one file. The following function merges all the results:

use \Codeception\Task\MergeReports;

     function parallelMergeResults()
    {
        $merge = $this->taskMergeXmlReports();
        for ($i=1; $i<=4; $i++) {
            $merge->from("tests/_output/tests/_log/result_$i.xml");
        }
        $merge->into("tests/_output/tests/_log/result.xml")
            ->run();
    }

Execute the commmand robo.phar parallel:merge-results to merge results.

You can put the two fuctions together in one function as follows:

   function parallelAll()
    {
        $result = $this->parallelRun();
        $this->parallelMergeResults();
        return $result;
    }

Execute the commmand robo.phar parallel:all to execute Codeception tests in parallel as well as merge results.

More details on parallel execution in Codeception available here.

codeception-browserstack's People

Contributors

umangsardesai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.