Skip to content

Commit 38aa3a4

Browse files
committed
Merge pull request php-webdriver#126 from cbergau/master
Add a second test suite for functional tests. Refactor RemoteWebDriver
2 parents 3e41d87 + ffa428a commit 38aa3a4

23 files changed

+106
-48
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ To run unit tests simply run:
5858

5959
./vendor/bin/phpunit -c ./tests
6060

61+
Note: For the functional test suite, a running selenium server is required.
62+
6163
## MORE INFORMATION
6264

6365
Check out the Selenium docs and wiki at http://docs.seleniumhq.org/docs/ and https://code.google.com/p/selenium/wiki

lib/remote/RemoteWebDriver.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,11 @@ public static function create(
4141
'name' => 'newSession',
4242
'parameters' => array('desiredCapabilities' => $desired_capabilities),
4343
);
44-
$response = HttpCommandExecutor::remoteExecute(
45-
$command,
46-
array(
47-
CURLOPT_CONNECTTIMEOUT_MS => $timeout_in_ms,
48-
)
49-
);
5044

45+
$response = static::remoteExecuteHttpCommand($timeout_in_ms, $command);
5146
$driver = new static();
52-
$executor = new HttpCommandExecutor(
53-
$url,
54-
$response['sessionId']
55-
);
47+
$executor = static::createHttpCommandExecutor($url, $response);
48+
5649
return $driver->setCommandExecutor($executor);
5750
}
5851

@@ -76,6 +69,34 @@ public static function createBySessionID(
7669
return $driver;
7770
}
7871

72+
/**
73+
* @param string $url
74+
* @param array $response
75+
* @return HttpCommandExecutor
76+
*/
77+
public static function createHttpCommandExecutor($url, $response) {
78+
$executor = new HttpCommandExecutor(
79+
$url,
80+
$response['sessionId']
81+
);
82+
return $executor;
83+
}
84+
85+
/**
86+
* @param int $timeout_in_ms
87+
* @param array $command
88+
* @return array
89+
*/
90+
public static function remoteExecuteHttpCommand($timeout_in_ms, $command) {
91+
$response = HttpCommandExecutor::remoteExecute(
92+
$command,
93+
array(
94+
CURLOPT_CONNECTTIMEOUT_MS => $timeout_in_ms,
95+
)
96+
);
97+
return $response;
98+
}
99+
79100
/**
80101
* Close the current window.
81102
*

tests/__init__.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<?php
22

33
require_once __DIR__ . '/../lib/__init__.php';
4+
require_once __DIR__ . '/functional/WebDriverTestCase.php';

tests/ExampleTestCase.php renamed to tests/functional/BaseTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
require_once('__init__.php');
17-
18-
/**
19-
* An example test case for php-webdriver.
20-
*
21-
* Try running it by
22-
* '../vendor/phpunit/phpunit/phpunit.php ExampleTestCase.php'
23-
*/
24-
class ExampleTestCase extends BasePHPWebDriverTestCase {
16+
class BaseTest extends WebDriverTestCase {
2517

26-
public function testTestPageTitle() {
18+
public function testGetTitle() {
2719
$this->driver->get($this->getTestPath('index.html'));
2820
self::assertEquals(
2921
'php-webdriver test page',
3022
$this->driver->getTitle()
3123
);
3224
}
3325

34-
public function testTestPageWelcome() {
26+
public function testGetText() {
3527
$this->driver->get($this->getTestPath('index.html'));
3628
self::assertEquals(
3729
'Welcome to the facebook/php-webdriver testing page.',
3830
$this->driver->findElement(WebDriverBy::id('welcome'))->getText()
3931
);
4032
}
33+
34+
public function testGetById() {
35+
$this->driver->get($this->getTestPath('index.html'));
36+
self::assertEquals(
37+
'Test by ID',
38+
$this->driver->findElement(WebDriverBy::id('id_test'))->getText()
39+
);
40+
}
4141
}

tests/FileUploadTestCase.php renamed to tests/functional/FileUploadTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
require_once('__init__.php');
17-
1816
/**
1917
* An example test case for php-webdriver.
2018
*
2119
* Try running it by
2220
* '../vendor/phpunit/phpunit/phpunit.php ExampleTestCase.php'
2321
*/
24-
class ExampleTestCase extends BasePHPWebDriverTestCase {
22+
class FileUploadTest extends WebDriverTestCase {
2523

2624
public function testFileUploading() {
2725
$this->driver->get($this->getTestPath('upload.html'));

tests/BasePHPWebDriverTestCase.php renamed to tests/functional/WebDriverTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
/**
1717
* The base class for test cases.
1818
*/
19-
class BasePHPWebDriverTestCase extends PHPUnit_Framework_TestCase {
19+
class WebDriverTestCase extends PHPUnit_Framework_TestCase {
2020

21+
/** @var RemoteWebDriver $driver */
2122
protected $driver;
2223

2324
protected function setUp() {

tests/html/index.html renamed to tests/functional/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
</head>
55
<body>
66
<h1 id='welcome'>Welcome to the facebook/php-webdriver testing page.</h1>
7+
<p id="id_test">Test by ID</p>
78
</body>
89
</html>
File renamed without changes.

0 commit comments

Comments
 (0)