Skip to content

Commit 55fb15b

Browse files
authored
Merge pull request #10 from alexpott/w3c-session-fix
Fix w3c false issues
2 parents cc9c601 + 84a2b40 commit 55fb15b

File tree

8 files changed

+113
-28
lines changed

8 files changed

+113
-28
lines changed

.ddev/docker-compose.selenium.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,23 @@ services:
1919
- ddev-global-cache:/mnt/ddev-global-cache
2020
chrome:
2121
container_name: ddev-${DDEV_SITENAME}-chrome
22-
image: selenium/standalone-chrome:latest
22+
image: selenium/standalone-chromium:latest
23+
labels:
24+
com.ddev.site-name: ${DDEV_SITENAME}
25+
com.ddev.approot: $DDEV_APPROOT
26+
shm_size: 2gb
27+
environment:
28+
- VIRTUAL_HOST=$DDEV_HOSTNAME
29+
links:
30+
- web:web
31+
external_links:
32+
- ddev-router:${DDEV_SITENAME}.${DDEV_TLD}
33+
volumes:
34+
- ".:/mnt/ddev_config:ro"
35+
- ddev-global-cache:/mnt/ddev-global-cache
36+
oldchrome:
37+
container_name: ddev-${DDEV_SITENAME}-oldchrome
38+
image: selenium/standalone-chrome:4.8
2339
labels:
2440
com.ddev.site-name: ${DDEV_SITENAME}
2541
com.ddev.approot: $DDEV_APPROOT

lib/WebDriver/WebDriver.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public function session($browserName = Browser::FIREFOX, $desiredCapabilities =
6161
};
6262

6363
$w3c_mode = true;
64-
if (isset($desiredCapabilities['w3c']) && $desiredCapabilities['w3c'] === false) {
64+
if (
65+
(isset($desiredCapabilities['w3c']) && $desiredCapabilities['w3c'] === false) ||
66+
(isset($desiredCapabilities['goog:chromeOptions']['w3c']) && $desiredCapabilities['goog:chromeOptions']['w3c'] === false)
67+
) {
6568
$w3c_mode = false;
6669
}
6770

@@ -77,32 +80,25 @@ public function session($browserName = Browser::FIREFOX, $desiredCapabilities =
7780
$parameters['capabilities']['alwaysMatch'] = $requiredCapabilities;
7881
}
7982

80-
try {
81-
$result = $this->curl(
82-
'POST',
83-
'/session',
84-
$parameters,
85-
array(CURLOPT_FOLLOWLOCATION => true)
86-
);
87-
} catch (\Exception $e) {
88-
// fallback to legacy JSON Wire Protocol
89-
$capabilities = $desiredCapabilities ?: array();
90-
$capabilities[Capability::BROWSER_NAME] = $browserName;
91-
92-
$parameters = array('desiredCapabilities' => $capabilities);
93-
94-
if (is_array($requiredCapabilities) && count($requiredCapabilities)) {
95-
$parameters['requiredCapabilities'] = $requiredCapabilities;
96-
}
97-
98-
$result = $this->curl(
99-
'POST',
100-
'/session',
101-
$parameters,
102-
array(CURLOPT_FOLLOWLOCATION => true)
103-
);
83+
if (!$w3c_mode) {
84+
// fallback to legacy JSON Wire Protocol
85+
$capabilities = $desiredCapabilities ?: array();
86+
$capabilities[Capability::BROWSER_NAME] = $browserName;
87+
88+
$parameters = array('desiredCapabilities' => $capabilities);
89+
90+
if (is_array($requiredCapabilities) && count($requiredCapabilities)) {
91+
$parameters['requiredCapabilities'] = $requiredCapabilities;
92+
}
10493
}
10594

95+
$result = $this->curl(
96+
'POST',
97+
'/session',
98+
$parameters,
99+
array(CURLOPT_FOLLOWLOCATION => true)
100+
);
101+
106102
$this->capabilities = isset($result['value']['capabilities']) ? $result['value']['capabilities'] : null;
107103
$session = new Session($result['sessionUrl'], $this->capabilities);
108104

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2021-2022 Anthon Pang. All Rights Reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @package WebDriver
19+
*
20+
* @author Anthon Pang <apang@softwaredevelopment.ca>
21+
*/
22+
23+
namespace Test\WebDriver;
24+
25+
/**
26+
* ChromeDriver
27+
*
28+
* @package WebDriver
29+
*
30+
* @group Functional
31+
*/
32+
class ChromeDriverNonW3CTest extends ChromeDriverTest
33+
{
34+
protected $w3c = false;
35+
}

test/Test/WebDriver/ChromeDriverTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ChromeDriverTest extends WebDriverTestBase
3737
{
3838
protected $testWebDriverRootUrl = 'http://localhost:9515';
3939
protected $testWebDriverName = 'chromedriver';
40+
protected $w3c = true;
4041
protected $status = null;
4142

4243
protected function setUp(): void
@@ -46,7 +47,7 @@ protected function setUp(): void
4647
$this->status = $this->driver->status();
4748
$this->session = $this->driver->session(Browser::CHROME, [
4849
'goog:chromeOptions' => [
49-
'w3c' => true,
50+
'w3c' => $this->w3c,
5051
'args' => [
5152
'--no-sandbox',
5253
'--ignore-certificate-errors',
@@ -72,5 +73,6 @@ public function testStatus()
7273
$this->assertEquals(1, $this->status['ready'], 'Chromedriver is not ready');
7374
$this->assertEquals('ChromeDriver ready for new sessions.', $this->status['message'], 'Chromedriver is not ready');
7475
$this->assertNotEmpty($this->status['os'], 'OS info not detected');
76+
$this->assertSame($this->w3c, $this->session->isW3c());
7577
}
7678
}

test/Test/WebDriver/Selenium4ChromeWebDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function setUp(): void
2525
$this->status = $this->driver->status();
2626
$this->session = $this->driver->session(Browser::CHROME, [
2727
'goog:chromeOptions' => [
28-
'w3c' => true,
28+
'w3c' => $this->w3c,
2929
'args' => [
3030
'--no-sandbox',
3131
'--ignore-certificate-errors',
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Test\WebDriver;
4+
5+
use WebDriver\Browser;
6+
7+
/**
8+
* Selenium WebDriver
9+
*
10+
* @package WebDriver
11+
*
12+
* @group Functional
13+
*/
14+
class Selenium4dot8ChromeWebDriverNonW3CTest extends Selenium4dot8ChromeWebDriverTest
15+
{
16+
protected $w3c = FALSE;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Test\WebDriver;
4+
5+
use WebDriver\Browser;
6+
7+
/**
8+
* Selenium WebDriver
9+
*
10+
* @package WebDriver
11+
*
12+
* @group Functional
13+
*/
14+
class Selenium4dot8ChromeWebDriverTest extends Selenium4ChromeWebDriverTest
15+
{
16+
protected $testWebDriverRootUrl = 'http://oldchrome:4444';
17+
}

test/Test/WebDriver/SeleniumWebDriverTestBase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ abstract class SeleniumWebDriverTestBase extends WebDriverTestBase
1414
protected $testWebDriverRootUrl = '';
1515
protected $testWebDriverName = 'selenium';
1616
protected $status = null;
17+
protected $w3c = true;
1718

1819
/**
1920
* Test driver status
@@ -23,5 +24,6 @@ public function testStatus()
2324
$this->assertEquals(1, $this->status['ready'], 'Selenium is not ready');
2425
$this->assertEquals('Selenium Grid ready.', $this->status['message'], 'Selenium is not ready');
2526
$this->assertNotEmpty($this->status['nodes'][0]['osInfo'], 'OS info not detected');
27+
$this->assertSame($this->w3c, $this->session->isW3c());
2628
}
2729
}

0 commit comments

Comments
 (0)