|
| 1 | +# Documentation to write parallel tests in PHP |
| 2 | + |
| 3 | +1. Install composer on your computer. Please follow instructions given on http://getcomposer.org/doc/00-intro.md. For this documentation composer.phar was renamed as composer and placed in /usr/local/bin(could be placed in any folder included in system path). |
| 4 | +2. In your composer.json add enteries for paratest and webdriver. PHP Unit is included as dependency of paratest so will be also installed. This composer.json should be placed in project root and should look like: |
| 5 | +``` |
| 6 | +{ |
| 7 | + "require": { |
| 8 | + "brianium/paratest": "dev-master", |
| 9 | + "facebook/webdriver": "0.1" |
| 10 | + } |
| 11 | +} |
| 12 | +``` |
| 13 | +for php5.4+ please use dev-master version of facebook/webdriver and for php versions less then 5.3 please use facebook/webdriver version 0.1. |
| 14 | +3. Install dependencies using composure. Please call bellow command in the project root containing composer.json |
| 15 | +``` |
| 16 | +composer install |
| 17 | +``` |
| 18 | +4. Or we can update dependencies using |
| 19 | +``` |
| 20 | +composer update |
| 21 | +``` |
| 22 | +5. To use PHPUnit test please create phpunit.xml and place following code in it: |
| 23 | +``` |
| 24 | +<?xml version="1.0" encoding="UTF-8"?> |
| 25 | +<phpunit backupGlobals="false" |
| 26 | + backupStaticAttributes="false" |
| 27 | + colors="true" |
| 28 | + convertErrorsToExceptions="true" |
| 29 | + convertNoticesToExceptions="true" |
| 30 | + convertWarningsToExceptions="true" |
| 31 | + processIsolation="false" |
| 32 | + stopOnFailure="false" |
| 33 | + syntaxCheck="false"> |
| 34 | + |
| 35 | + <testsuites> |
| 36 | + <testsuite name="ParaTest Fixtures"> |
| 37 | + <directory>./test/</directory> |
| 38 | + </testsuite> |
| 39 | + </testsuites> |
| 40 | +</phpunit> |
| 41 | +``` |
| 42 | +testsuites entry is used to integrate ParaTest with PHPUnit. In this tutorial tests are placed in test folder placed in the root folder of project. |
| 43 | +6. Create test folder in project root if not present and then create SeleniumTest.php with following code in test folder |
| 44 | +``` |
| 45 | +<?php |
| 46 | +require 'vendor/autoload.php'; |
| 47 | +class SeleniumTest extends PHPUnit_Framework_TestCase { |
| 48 | + public function testGoogle() { |
| 49 | + $web_driver = new RemoteWebDriver( |
| 50 | + "http://{your-username}:{your-passkey}@hub.browserstack.com/wd/hub", |
| 51 | + array("platform"=>"WINDOWS") |
| 52 | + ); |
| 53 | + $web_driver->get("http://www.google.com"); |
| 54 | + print $web_driver->getTitle(); |
| 55 | + $element = $web_driver->findElement(WebDriverBy::name("q")); |
| 56 | + if ($element) { |
| 57 | + $element->sendKeys("Browserstack"); |
| 58 | + $element->submit(); |
| 59 | + } |
| 60 | + $web_driver->quit(); |
| 61 | + } |
| 62 | + public function testBrowserStack() { |
| 63 | + $web_driver = new RemoteWebDriver( |
| 64 | + "http://{your-username}:{your-passkey}@hub.browserstack.com/wd/hub", |
| 65 | + array("platform"=>"WINDOWS") |
| 66 | + ); |
| 67 | + $web_driver->get("http://www.browserstack.com"); |
| 68 | + print $web_driver->getTitle(); |
| 69 | + $web_driver->quit(); |
| 70 | + } |
| 71 | + public function testFacebook() { |
| 72 | + $web_driver = new RemoteWebDriver( |
| 73 | + "http://{your-username}:{your-passkey}@hub.browserstack.com/wd/hub", |
| 74 | + array("platform"=>"WINDOWS") |
| 75 | + ); |
| 76 | + $web_driver->get("http://www.facebook.com"); |
| 77 | + print $web_driver->getTitle(); |
| 78 | + $web_driver->quit(); |
| 79 | + } |
| 80 | +} |
| 81 | +?> |
| 82 | +``` |
| 83 | +7. To run this UnitTests in parallel please call following command: |
| 84 | +``` |
| 85 | +vendor/bin/paratest -p 3 -f --phpunit=vendor/bin/phpunit test/SeleniumTest.php |
| 86 | +``` |
0 commit comments