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

Commit bd15029

Browse files
authored
Merge pull request #696 from OndraM/feature/env-name
Change environment variable defining path to ChromeDriver executable
2 parents 5dbadd6 + 6ee27df commit bd15029

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111
- Revert no longer needed workaround for Chromedriver bug [2943](https://bugs.chromium.org/p/chromedriver/issues/detail?id=2943).
1212
- Allow installation of Symfony 5 components.
13+
- Rename environment variable used to pass path to ChromeDriver executable from `webdriver.chrome.driver` to `WEBDRIVER_CHROME_DRIVER`. However the old one also still works to keep backward compatibility
1314

1415
### Fixed
1516
- `WebDriverExpectedCondition::presenceOfElementLocated()` works correctly when used within `WebDriverExpectedCondition::not()`.

lib/Chrome/ChromeDriverService.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@
1919

2020
class ChromeDriverService extends DriverService
2121
{
22-
// The environment variable storing the path to the chrome driver executable.
22+
/**
23+
* The environment variable storing the path to the chrome driver executable.
24+
* @deprecated Use ChromeDriverService::CHROME_DRIVER_EXECUTABLE
25+
*/
2326
const CHROME_DRIVER_EXE_PROPERTY = 'webdriver.chrome.driver';
27+
// The environment variable storing the path to the chrome driver executable
28+
const CHROME_DRIVER_EXECUTABLE = 'WEBDRIVER_CHROME_DRIVER';
2429

2530
/**
2631
* @return static
2732
*/
2833
public static function createDefaultService()
2934
{
30-
$exe = getenv(self::CHROME_DRIVER_EXE_PROPERTY);
35+
$exe = getenv(self::CHROME_DRIVER_EXECUTABLE) ?: getenv(self::CHROME_DRIVER_EXE_PROPERTY);
3136
$port = 9515; // TODO: Get another port if the default port is used.
32-
$args = ["--port=$port"];
33-
$service = new static($exe, $port, $args);
37+
$args = ['--port=' . $port];
3438

35-
return $service;
39+
return new static($exe, $port, $args);
3640
}
3741
}

tests/functional/Chrome/ChromeDriverServiceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function setUp()
3434
public function testShouldStartAndStopServiceCreatedUsingShortcutConstructor()
3535
{
3636
// The createDefaultService() method expect path to the executable to be present in the environment variable
37-
putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=' . getenv('CHROMEDRIVER_PATH'));
37+
putenv(ChromeDriverService::CHROME_DRIVER_EXECUTABLE . '=' . getenv('CHROMEDRIVER_PATH'));
3838

3939
$driverService = ChromeDriverService::createDefaultService();
4040

@@ -66,7 +66,7 @@ public function testShouldStartAndStopServiceCreatedUsingDefaultConstructor()
6666

6767
public function testShouldThrowExceptionIfExecutableCannotBeFound()
6868
{
69-
putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=/not/existing');
69+
putenv(ChromeDriverService::CHROME_DRIVER_EXECUTABLE . '=/not/existing');
7070

7171
$this->expectException(\Exception::class);
7272
$this->expectExceptionMessage('\'/not/existing\' is not a file.');
@@ -75,7 +75,7 @@ public function testShouldThrowExceptionIfExecutableCannotBeFound()
7575

7676
public function testShouldThrowExceptionIfExecutableIsNotExecutable()
7777
{
78-
putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=' . __FILE__);
78+
putenv(ChromeDriverService::CHROME_DRIVER_EXECUTABLE . '=' . __FILE__);
7979

8080
$this->expectException(\Exception::class);
8181
$this->expectExceptionMessage('is not executable');

tests/functional/Chrome/ChromeDriverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ protected function tearDown()
4646
public function testShouldStartChromeDriver()
4747
{
4848
// The createDefaultService() method expect path to the executable to be present in the environment variable
49-
putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=' . getenv('CHROMEDRIVER_PATH'));
49+
putenv(ChromeDriverService::CHROME_DRIVER_EXECUTABLE . '=' . getenv('CHROMEDRIVER_PATH'));
5050

5151
// Add --no-sandbox as a workaround for Chrome crashing: https://github.com/SeleniumHQ/selenium/issues/4961
5252
$chromeOptions = new ChromeOptions();
53-
$chromeOptions->addArguments(['--no-sandbox']);
53+
$chromeOptions->addArguments(['--no-sandbox', '--headless']);
5454
$desiredCapabilities = DesiredCapabilities::chrome();
5555
$desiredCapabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
5656

0 commit comments

Comments
 (0)