|
1 | | -# Phpunit testing using Selenium2TestCase |
2 | | -1. Do composer install |
3 | | -2. To run test execute in shell vendor/bin/phpunit test/ |
| 1 | +# Documentation to write simple 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 phpunit and webdriver. This composer.json should be placed in project root and should look like: |
| 5 | +``` |
| 6 | +{ |
| 7 | + "require": { |
| 8 | + "phpunit/phpunit-selenium": "dev-master", |
| 9 | + "facebook/webdriver": "dev-master" |
| 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. Create test folder in project root if not present and then create SeleniumTest.php with following code in test folder |
| 23 | +``` |
| 24 | +<?php |
| 25 | +require 'vendor/autoload.php'; |
| 26 | +define('BROWSERSTACK_USER', 'BROWSERSTACK_USERNAME'); |
| 27 | +define('BROWSERSTACK_KEY', 'BROWSERSTACK_KEY'); |
| 28 | +class WebTest extends PHPUnit_Extensions_Selenium2TestCase |
| 29 | +{ |
| 30 | + public static $browsers = array( |
| 31 | + array( |
| 32 | + 'browserName' => 'chrome', |
| 33 | + 'host' => 'hub.browserstack.com', |
| 34 | + 'port' => 80, |
| 35 | + 'desiredCapabilities' => array( |
| 36 | + 'version' => '30', |
| 37 | + 'browserstack.user' => BROWSERSTACK_USER, |
| 38 | + 'browserstack.key' => BROWSERSTACK_KEY, |
| 39 | + 'os' => 'OS X', |
| 40 | + 'os_version' => 'Mountain Lion' |
| 41 | + ) |
| 42 | + ), |
| 43 | + array( |
| 44 | + 'browserName' => 'chrome', |
| 45 | + 'host' => 'hub.browserstack.com', |
| 46 | + 'port' => 80, |
| 47 | + 'desiredCapabilities' => array( |
| 48 | + 'version' => '30', |
| 49 | + 'browserstack.user' => BROWSERSTACK_USER, |
| 50 | + 'browserstack.key' => BROWSERSTACK_KEY, |
| 51 | + 'os' => 'Windows', |
| 52 | + 'os_version' => '8.1' |
| 53 | + ) |
| 54 | + ) |
| 55 | + ); |
| 56 | + protected function setUp() |
| 57 | + { |
| 58 | + parent::setUp(); |
| 59 | + $this->setBrowserUrl('http://www.example.com/'); |
| 60 | + } |
| 61 | + |
| 62 | + public function testTitle() |
| 63 | + { |
| 64 | + $this->url('http://www.example.com/'); |
| 65 | + $this->assertEquals('Example Domain', $this->title()); |
| 66 | + } |
| 67 | + public function testGoogle() |
| 68 | + { |
| 69 | + $this->url('http://www.google.com/'); |
| 70 | + $element = $this->byName('q'); |
| 71 | + $element->click(); |
| 72 | + $this->keys('Browserstack'); |
| 73 | + $button = $this->byName('btnG'); |
| 74 | + $button->click(); |
| 75 | + $this->assertEquals('Browserstack - Google zoeken', $this->title()); |
| 76 | + } |
| 77 | +} |
| 78 | +?> |
| 79 | +``` |
| 80 | +6. Replace BROWSERSTACK_KEY and BROWSERSTACK_USERNAME with your BrowserStack Username and access key to run the tests. |
| 81 | +To run this UnitTests in please call following command: |
| 82 | +``` |
| 83 | +vendor/bin/phpunit test/ |
| 84 | +``` |
0 commit comments