Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 1b0facc

Browse files
committed
[unittest] Let's do testing!
- Add the phpunit to composer.json - Add an example test case It should be a good start :D
1 parent ae9a5bf commit 1b0facc

File tree

6 files changed

+116
-2
lines changed

6 files changed

+116
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.phar
2+
composer.lock
3+
vendor

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"name": "facebook/webdriver",
3-
"description": "A php client for WebDriver",
3+
"description": "A php client for WebDriver",
4+
"keywords": ["webdriver", "selenium", "php", "facebook"],
45
"homepage": "https://github.com/facebook/php-webdriver",
6+
"type": "library",
57
"license": "Apache-2.0",
68
"require": {
7-
"php": ">=5.3.19"
9+
"php": ">=5.3.19",
10+
"phpunit/phpunit": "3.7.*"
811
},
912
"autoload": {
1013
"classmap": ["lib/"]

tests/BasePHPWebDriverTestCase.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
// Copyright 2004-present Facebook. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
/**
17+
* The base class for test cases.
18+
*/
19+
class BasePHPWebDriverTestCase extends PHPUnit_Framework_TestCase {
20+
21+
protected $driver;
22+
23+
protected function setUp() {
24+
$this->driver = RemoteWebDriver::create(
25+
'http://localhost:4444/wd/hub',
26+
array(
27+
WebDriverCapabilityType::BROWSER_NAME
28+
=> WebDriverBrowserType::HTMLUNIT,
29+
)
30+
);
31+
}
32+
33+
protected function tearDown() {
34+
$this->driver->quit();
35+
}
36+
37+
/**
38+
* Get the URL of the test html.
39+
*/
40+
protected function getTestPath($path) {
41+
return 'file:///'.dirname(__FILE__).'/html/'.$path;
42+
}
43+
}

tests/ExampleTestCase.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
// Copyright 2004-present Facebook. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
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 {
25+
26+
public function testTestPageTitle() {
27+
$this->driver->get($this->getTestPath('index.html'));
28+
self::assertEquals(
29+
'php-webdriver test page',
30+
$this->driver->getTitle()
31+
);
32+
}
33+
34+
public function testTestPageWelcome() {
35+
$this->driver->get($this->getTestPath('index.html'));
36+
self::assertEquals(
37+
'Welcome to the facebook/php-webdriver testing page.',
38+
$this->driver->findElement(WebDriverBy::id('welcome'))->getText()
39+
);
40+
}
41+
}

tests/__init__.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
// Copyright 2004-present Facebook. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once('BasePHPWebDriverTestCase.php');

tests/html/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>php-webdriver test page</title>
4+
</head>
5+
<body>
6+
<h1 id='welcome'>Welcome to the facebook/php-webdriver testing page.</h1>
7+
</body>
8+
</html>

0 commit comments

Comments
 (0)