Skip to content

Commit 0e0f5dd

Browse files
committed
update readme and tests
1 parent 50e6f6d commit 0e0f5dd

7 files changed

Lines changed: 110 additions & 15 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
phpunit-browserstack
2+
=========
3+
4+
This repository provides information and helpful tweaks to run your PhpUnit tests on the BrowserStack selenium cloud infrastructure.
5+
6+
You can run parallel as well as single test on the BrowserStack. Follow the steps in the respective folders for further information.
7+
8+
9+
###Further Reading
10+
- [PHPUnit](https://phpunit.de/)
11+
- [BrowserStack documentation for Automate](https://www.browserstack.com/automate/ruby)
12+
13+
Happy Testing!

parallel-tests-phpunit/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ class SeleniumTest extends PHPUnit_Framework_TestCase {
8080
}
8181
?>
8282
```
83-
7. To run this UnitTests in parallel please call following command:
83+
7. Replace BROWSERSTACK_KEY and BROWSERSTACK_USERNAME with your BrowserStack Username and access key to run the tests.
84+
To run this UnitTests in parallel please call following command:
8485
```
8586
vendor/bin/paratest -p 3 -f --phpunit=vendor/bin/phpunit test/SeleniumTest.php
8687
```
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"brianium/paratest": "dev-master",
4-
"facebook/webdriver": "dev-master"
5-
}
3+
"brianium/paratest": "dev-master",
4+
"facebook/webdriver": "dev-master"
5+
}
66
}

parallel-tests-phpunit/test/SeleniumTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
class SeleniumTest extends PHPUnit_Framework_TestCase {
55

6-
protected static $user_id = "<Your Userid>";
7-
protected static $security_key = "<Your Security Key>";
6+
protected static $user_id = "BROWSERSTACK_USERNAME";
7+
protected static $security_key = "BROWSERSTACK_KEY";
88

99
public function testGoogle() {
1010
$url = "http://" . self::$user_id . ":" . self::$security_key . "@hub.browserstack.com/wd/hub";

tests-phpunit/README.md

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,84 @@
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+
```

tests-phpunit/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"phpunit/phpunit-selenium": "dev-master",
4-
"facebook/webdriver": "dev-master"
5-
}
3+
"phpunit/phpunit-selenium": "dev-master",
4+
"facebook/webdriver": "dev-master"
5+
}
66
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
require 'vendor/autoload.php';
3-
define('BROWSERSTACK_USER', '<Set BrowserStack Username>');
4-
define('BROWSERSTACK_KEY', '<Set BrowserStack Key>');
3+
define('BROWSERSTACK_USER', 'BROWSERSTACK_USERNAME');
4+
define('BROWSERSTACK_KEY', 'BROWSERSTACK_KEY');
55
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
66
{
77
public static $browsers = array(
@@ -12,7 +12,7 @@ class WebTest extends PHPUnit_Extensions_Selenium2TestCase
1212
'desiredCapabilities' => array(
1313
'version' => '30',
1414
'browserstack.user' => BROWSERSTACK_USER,
15-
'browserstack.key' => 'XQWDewaJsUzqYJRv8zhr',
15+
'browserstack.key' => BROWSERSTACK_KEY,
1616
'os' => 'OS X',
1717
'os_version' => 'Mountain Lion'
1818
)

0 commit comments

Comments
 (0)