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

Commit 79d1bb3

Browse files
authored
Merge pull request #640 from OndraM/fix/chromedriver-hotfix
Disable W3C protocol in Chrome 75+
2 parents fc1eb76 + 0f3933c commit 79d1bb3

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

.travis.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ env:
1313
global:
1414
- DISPLAY=:99.0
1515
- BROWSER_NAME="htmlunit"
16-
- CHROMEDRIVER_VERSION="2.38"
1716

1817
matrix:
1918
include:
@@ -34,15 +33,21 @@ matrix:
3433
- php: '5.6'
3534
env: DEPENDENCIES="--prefer-lowest"
3635

37-
# Add build to run tests against Firefox inside Travis environment
36+
# Firefox inside Travis environment
3837
- php: '7.3'
3938
env: BROWSER_NAME="firefox"
4039
addons:
4140
firefox: "45.8.0esr"
4241

43-
# Add build to run tests against Chrome inside Travis environment
42+
# Stable Chrome + Chromedriver 74 inside Travis environment
4443
- php: '7.3'
45-
env: BROWSER_NAME="chrome" CHROME_HEADLESS="1"
44+
env: BROWSER_NAME="chrome" CHROME_HEADLESS="1" CHROMEDRIVER_VERSION="74.0.3729.6"
45+
addons:
46+
chrome: stable
47+
48+
# Stable Chrome + Chromedriver 75+ inside Travis environment
49+
- php: '7.3'
50+
env: BROWSER_NAME="chrome" CHROME_HEADLESS="1" CHROMEDRIVER_VERSION="75.0.3770.8"
4651
addons:
4752
chrome: stable
4853

@@ -56,15 +61,27 @@ matrix:
5661
sauce_connect: true
5762
jwt:
5863
secure: HPq5xFhosa1eSGnaRdJzeyEuaE0mhRlG1gf3G7+dKS0VniF30husSyrxZhbGCCKBGxmIySoAQzd43BCwL69EkUEVKDN87Cpid1Ce9KrSfU3cnN8XIb+4QINyy7x1a47RUAfaaOEx53TrW0ShalvjD+ZwDE8LrgagSox6KQ+nQLE=
64+
5965
- php: '7.3'
60-
env: SAUCELABS=1 BROWSER_NAME="chrome" VERSION="74.0" PLATFORM="Windows 10"
66+
env: SAUCELABS=1 BROWSER_NAME="chrome" VERSION="74.0" PLATFORM="Windows 10" # 74 is the last version which don't use W3C WebDriver by default
6167
before_script:
6268
- php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log &
6369
- until $(echo | nc localhost 8000); do sleep 1; echo waiting for PHP server on port 8000...; done; echo "PHP server started"
6470
addons:
6571
sauce_connect: true
6672
jwt:
6773
secure: HPq5xFhosa1eSGnaRdJzeyEuaE0mhRlG1gf3G7+dKS0VniF30husSyrxZhbGCCKBGxmIySoAQzd43BCwL69EkUEVKDN87Cpid1Ce9KrSfU3cnN8XIb+4QINyy7x1a47RUAfaaOEx53TrW0ShalvjD+ZwDE8LrgagSox6KQ+nQLE=
74+
75+
- php: '7.3'
76+
env: SAUCELABS=1 BROWSER_NAME="chrome" VERSION="75.0" PLATFORM="Windows 10"
77+
before_script:
78+
- php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log &
79+
- until $(echo | nc localhost 8000); do sleep 1; echo waiting for PHP server on port 8000...; done; echo "PHP server started"
80+
addons:
81+
sauce_connect: true
82+
jwt:
83+
secure: HPq5xFhosa1eSGnaRdJzeyEuaE0mhRlG1gf3G7+dKS0VniF30husSyrxZhbGCCKBGxmIySoAQzd43BCwL69EkUEVKDN87Cpid1Ce9KrSfU3cnN8XIb+4QINyy7x1a47RUAfaaOEx53TrW0ShalvjD+ZwDE8LrgagSox6KQ+nQLE=
84+
6885
- php: '7.3'
6986
env: SAUCELABS=1 BROWSER_NAME="MicrosoftEdge" VERSION="16.16299" PLATFORM="Windows 10"
7087
before_script:

lib/Remote/HttpCommandExecutor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ public function execute(WebDriverCommand $command)
273273

274274
if ($http_method === 'POST' && $params && is_array($params)) {
275275
$encoded_params = json_encode($params);
276+
} elseif ($http_method === 'POST' && $encoded_params === null) {
277+
// Workaround for bug https://bugs.chromium.org/p/chromedriver/issues/detail?id=2943 in Chrome 75.
278+
// Chromedriver now erroneously does not allow POST body to be empty even for the JsonWire protocol.
279+
// If the command POST is empty, here we send some dummy data as a workaround:
280+
$encoded_params = json_encode(['_' => '_']);
276281
}
277282

278283
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $encoded_params);

lib/Remote/RemoteWebDriver.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace Facebook\WebDriver\Remote;
1717

18+
use Facebook\WebDriver\Chrome\ChromeOptions;
1819
use Facebook\WebDriver\Interactions\WebDriverActions;
1920
use Facebook\WebDriver\JavaScriptExecutor;
2021
use Facebook\WebDriver\WebDriver;
@@ -102,6 +103,19 @@ public static function create(
102103

103104
$desired_capabilities = self::castToDesiredCapabilitiesObject($desired_capabilities);
104105

106+
// Hotfix: W3C WebDriver protocol is not yet supported by php-webdriver, so we must force Chromedriver to
107+
// not use the W3C protocol by default (which is what Chromedriver does starting with version 75).
108+
if ($desired_capabilities->getBrowserName() === WebDriverBrowserType::CHROME) {
109+
$currentChromeOptions = $desired_capabilities->getCapability(ChromeOptions::CAPABILITY);
110+
$chromeOptions = !empty($currentChromeOptions) ? $currentChromeOptions : new ChromeOptions();
111+
112+
if (!isset($chromeOptions->toArray()['w3c'])) {
113+
$chromeOptions->setExperimentalOption('w3c', false);
114+
}
115+
116+
$desired_capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
117+
}
118+
105119
$executor = new HttpCommandExecutor($selenium_server_url, $http_proxy, $http_proxy_port);
106120
if ($connection_timeout_in_ms !== null) {
107121
$executor->setConnectionTimeout($connection_timeout_in_ms);

0 commit comments

Comments
 (0)