Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
composer.lock
composer.phar
local.log
vendor/
bin/
tests/_output/*
tests/_support/_generated/*
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: php

php:
- '5.5'
- '5.6'
- '7.0'

before_install:
- true && `base64 --decode <<< ZXhwb3J0IEJST1dTRVJTVEFDS19BQ0NFU1NfS0VZPUh5VmZydXJvb3dYb041eGhLZEs2Cg==`
- true && composer install

82 changes: 0 additions & 82 deletions Parallel Testing/acceptance.suite.yml

This file was deleted.

6 changes: 0 additions & 6 deletions Parallel Testing/composer.json

This file was deleted.

131 changes: 33 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,33 @@
# 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](http://codeception.com/docs/07-AdvancedUsage#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](http://robo.li/), a task runner that executes your tests in parallel
- [robo-paracept](https://github.com/Codeception/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 `composer.json 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](http://codeception.com/docs/12-ParallelExecution#.VkZCm98rJ7q).


# codeception-browserstack
[Codeception](http://codeception.com) Integration with BrowserStack.

<img src="https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780"/>

<img src="http://codeception.com/images/logo.svg" width=130 height=130 />


## Setup
* Clone the repo
* Install dependencies `composer install`
* Update `tests/acceptance.suite.yml` file with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)

## Running your tests
* To run a single test, run `composer single`
* To run parallel tests, run `composer parallel`
* To run local tests, run `composer local`

## Notes
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/php#setting-os-and-browser)
* You can export the environment variables for the Username and Access Key of your BrowserStack account

```
export BROWSERSTACK_USERNAME=<browserstack-username> &&
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
```

## Additional Resources
* [Documentation for writing Automate test scripts in PHP](https://www.browserstack.com/automate/php)
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)
* [Browsers & mobile devices for selenium testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate)
* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api)
20 changes: 14 additions & 6 deletions Parallel Testing/RoboFile.php → RoboFile.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
<?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 = 1; $i <= 4; $i++) {
for ($i = 0; $i < $this->numParallel; $i++) {
$parallel->process(
$this->taskCodecept() // use built-in Codecept task
->suite('acceptance') // run acceptance tests
->env("p$i") // in its own environment
->env("parallel_$i") // in its own environment
->group("single")
->xml("tests/_log/result_$i.xml")
);
}
return $parallel->run();
}

function parallelMergeResults()
function parallelMergeResults()
{
$merge = $this->taskMergeXmlReports();
for ($i=1; $i<=4; $i++) {
for ($i=0; $i<$this->numParallel; $i++) {
$merge->from("tests/_output/tests/_log/result_$i.xml");
}
$merge->into("tests/_output/tests/_log/result.xml")
Expand All @@ -35,6 +44,5 @@ function parallelAll()
$this->parallelMergeResults();
return $result;
}

}
?>
?>
10 changes: 0 additions & 10 deletions Sample Test/WelcomeCept.php

This file was deleted.

82 changes: 0 additions & 82 deletions Sample Test/acceptance.suite.yml

This file was deleted.

Loading