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

Commit 5522ce1

Browse files
authored
Merge pull request #490 from OndraM/feature/chromedriver-tests
Add tests for ChromeDriverService and ChromeDriver
2 parents 776e50a + c85b872 commit 5522ce1

File tree

4 files changed

+154
-4
lines changed

4 files changed

+154
-4
lines changed

.travis.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ matrix:
2929

3030
# Build with lowest possible dependencies
3131
- php: 7.1
32-
env: dependencies="--prefer-lowest"
32+
env: DEPENDENCIES="--prefer-lowest"
33+
34+
# Chrome on Travis build with lowest possible dependencies
35+
- php: 7.1
36+
env: BROWSER_NAME="chrome" CHROME_HEADLESS="1" DEPENDENCIES="--prefer-lowest"
37+
addons:
38+
chrome: beta
3339

3440
# Saucelabs builds
3541
- php: 7.1
@@ -77,11 +83,11 @@ before_install:
7783
- travis_retry composer self-update
7884

7985
install:
80-
- travis_retry composer update --no-interaction $dependencies
86+
- travis_retry composer update --no-interaction $DEPENDENCIES
8187

8288
before_script:
8389
- if [ "$BROWSER_NAME" = "chrome" ]; then mkdir chromedriver; wget -q -t 3 https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip; unzip chromedriver_linux64 -d chromedriver; fi
84-
- if [ "$BROWSER_NAME" = "chrome" ]; then export CHROMEDRIVER_PATH=./chromedriver/chromedriver; fi
90+
- if [ "$BROWSER_NAME" = "chrome" ]; then export CHROMEDRIVER_PATH=$PWD/chromedriver/chromedriver; fi
8591
- sh -e /etc/init.d/xvfb start
8692
- if [ ! -f jar/selenium-server-standalone-3.4.0.jar ]; then wget -q -t 3 -P jar https://selenium-release.storage.googleapis.com/3.4/selenium-server-standalone-3.4.0.jar; fi
8793
- java -Dwebdriver.firefox.marionette=false -Dwebdriver.chrome.driver="$CHROMEDRIVER_PATH" -jar jar/selenium-server-standalone-3.4.0.jar -log ./logs/selenium.log &

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "^5.4",
21+
"sebastian/environment": "^1.3.4 || ^2.0 || ^3.0",
2122
"friendsofphp/php-cs-fixer": "^2.0",
2223
"squizlabs/php_codesniffer": "^2.6",
2324
"php-mock/php-mock-phpunit": "^1.1",
24-
"satooshi/php-coveralls": "^1.0",
25+
"php-coveralls/php-coveralls": "^1.0.2",
26+
"guzzle/guzzle": "^3.4.1",
2527
"symfony/var-dumper": "^3.3"
2628
},
2729
"autoload": {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
namespace Facebook\WebDriver\Chrome;
17+
18+
/**
19+
* @group exclude-saucelabs
20+
* @covers Facebook\WebDriver\Chrome\ChromeDriverService
21+
* @covers Facebook\WebDriver\Remote\Service\DriverService
22+
*/
23+
class ChromeDriverServiceTest extends \PHPUnit_Framework_TestCase
24+
{
25+
protected function setUp()
26+
{
27+
if (!getenv('BROWSER_NAME') === 'chrome' || getenv('SAUCELABS') || !getenv('CHROMEDRIVER_PATH')) {
28+
$this->markTestSkipped('ChromeDriverServiceTest is run only when running against local chrome');
29+
}
30+
}
31+
32+
public function testShouldStartAndStopServiceCreatedUsingShortcutConstructor()
33+
{
34+
// The createDefaultService() method expect path to the executable to be present in the environment variable
35+
putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=' . getenv('CHROMEDRIVER_PATH'));
36+
37+
$driverService = ChromeDriverService::createDefaultService();
38+
39+
$this->assertSame('http://localhost:9515', $driverService->getURL());
40+
41+
$this->assertInstanceOf(ChromeDriverService::class, $driverService->start());
42+
$this->assertTrue($driverService->isRunning());
43+
44+
$this->assertInstanceOf(ChromeDriverService::class, $driverService->start());
45+
46+
$this->assertInstanceOf(ChromeDriverService::class, $driverService->stop());
47+
$this->assertFalse($driverService->isRunning());
48+
49+
$this->assertInstanceOf(ChromeDriverService::class, $driverService->stop());
50+
}
51+
52+
public function testShouldStartAndStopServiceCreatedUsingDefaultConstructor()
53+
{
54+
$driverService = new ChromeDriverService(getenv('CHROMEDRIVER_PATH'), 9515, ['--port=9515']);
55+
56+
$this->assertSame('http://localhost:9515', $driverService->getURL());
57+
58+
$driverService->start();
59+
$this->assertTrue($driverService->isRunning());
60+
61+
$driverService->stop();
62+
$this->assertFalse($driverService->isRunning());
63+
}
64+
65+
public function testShouldThrowExceptionIfExecutableCannotBeFound()
66+
{
67+
putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=/not/existing');
68+
69+
$this->expectException(\Exception::class);
70+
$this->expectExceptionMessage('\'/not/existing\' is not a file.');
71+
ChromeDriverService::createDefaultService();
72+
}
73+
74+
public function testShouldThrowExceptionIfExecutableIsNotExecutable()
75+
{
76+
putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=' . __FILE__);
77+
78+
$this->expectException(\Exception::class);
79+
$this->expectExceptionMessage('is not executable');
80+
ChromeDriverService::createDefaultService();
81+
}
82+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
namespace Facebook\WebDriver\Chrome;
17+
18+
use Facebook\WebDriver\Remote\RemoteWebDriver;
19+
use Facebook\WebDriver\Remote\Service\DriverCommandExecutor;
20+
21+
/**
22+
* @group exclude-saucelabs
23+
* @covers Facebook\WebDriver\Chrome\ChromeDriver
24+
*/
25+
class ChromeDriverTest extends \PHPUnit_Framework_TestCase
26+
{
27+
/** @var ChromeDriver */
28+
protected $driver;
29+
30+
protected function setUp()
31+
{
32+
if (!getenv('BROWSER_NAME') === 'chrome' || getenv('SAUCELABS') || !getenv('CHROMEDRIVER_PATH')) {
33+
$this->markTestSkipped('ChromeDriverServiceTest is run only when running against local chrome');
34+
}
35+
}
36+
37+
protected function tearDown()
38+
{
39+
if ($this->driver instanceof RemoteWebDriver && $this->driver->getCommandExecutor() !== null) {
40+
$this->driver->quit();
41+
}
42+
}
43+
44+
public function testShouldStartChromeDriver()
45+
{
46+
// The createDefaultService() method expect path to the executable to be present in the environment variable
47+
putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=' . getenv('CHROMEDRIVER_PATH'));
48+
49+
$this->driver = ChromeDriver::start();
50+
51+
$this->assertInstanceOf(ChromeDriver::class, $this->driver);
52+
$this->assertInstanceOf(DriverCommandExecutor::class, $this->driver->getCommandExecutor());
53+
54+
$this->driver->get('http://localhost:8000/');
55+
56+
$this->assertSame('http://localhost:8000/', $this->driver->getCurrentURL());
57+
58+
$this->driver->quit();
59+
}
60+
}

0 commit comments

Comments
 (0)