diff --git a/.ddev/docker-compose.selenium.yaml b/.ddev/docker-compose.selenium.yaml index 0da85cd..0e1c129 100644 --- a/.ddev/docker-compose.selenium.yaml +++ b/.ddev/docker-compose.selenium.yaml @@ -19,7 +19,23 @@ services: - ddev-global-cache:/mnt/ddev-global-cache chrome: container_name: ddev-${DDEV_SITENAME}-chrome - image: selenium/standalone-chrome:latest + image: selenium/standalone-chromium:latest + labels: + com.ddev.site-name: ${DDEV_SITENAME} + com.ddev.approot: $DDEV_APPROOT + shm_size: 2gb + environment: + - VIRTUAL_HOST=$DDEV_HOSTNAME + links: + - web:web + external_links: + - ddev-router:${DDEV_SITENAME}.${DDEV_TLD} + volumes: + - ".:/mnt/ddev_config:ro" + - ddev-global-cache:/mnt/ddev-global-cache + oldchrome: + container_name: ddev-${DDEV_SITENAME}-oldchrome + image: selenium/standalone-chrome:4.8 labels: com.ddev.site-name: ${DDEV_SITENAME} com.ddev.approot: $DDEV_APPROOT diff --git a/lib/WebDriver/WebDriver.php b/lib/WebDriver/WebDriver.php index 844616f..7e03494 100644 --- a/lib/WebDriver/WebDriver.php +++ b/lib/WebDriver/WebDriver.php @@ -61,7 +61,10 @@ public function session($browserName = Browser::FIREFOX, $desiredCapabilities = }; $w3c_mode = true; - if (isset($desiredCapabilities['w3c']) && $desiredCapabilities['w3c'] === false) { + if ( + (isset($desiredCapabilities['w3c']) && $desiredCapabilities['w3c'] === false) || + (isset($desiredCapabilities['goog:chromeOptions']['w3c']) && $desiredCapabilities['goog:chromeOptions']['w3c'] === false) + ) { $w3c_mode = false; } @@ -77,32 +80,25 @@ public function session($browserName = Browser::FIREFOX, $desiredCapabilities = $parameters['capabilities']['alwaysMatch'] = $requiredCapabilities; } - try { - $result = $this->curl( - 'POST', - '/session', - $parameters, - array(CURLOPT_FOLLOWLOCATION => true) - ); - } catch (\Exception $e) { - // fallback to legacy JSON Wire Protocol - $capabilities = $desiredCapabilities ?: array(); - $capabilities[Capability::BROWSER_NAME] = $browserName; - - $parameters = array('desiredCapabilities' => $capabilities); - - if (is_array($requiredCapabilities) && count($requiredCapabilities)) { - $parameters['requiredCapabilities'] = $requiredCapabilities; - } - - $result = $this->curl( - 'POST', - '/session', - $parameters, - array(CURLOPT_FOLLOWLOCATION => true) - ); + if (!$w3c_mode) { + // fallback to legacy JSON Wire Protocol + $capabilities = $desiredCapabilities ?: array(); + $capabilities[Capability::BROWSER_NAME] = $browserName; + + $parameters = array('desiredCapabilities' => $capabilities); + + if (is_array($requiredCapabilities) && count($requiredCapabilities)) { + $parameters['requiredCapabilities'] = $requiredCapabilities; + } } + $result = $this->curl( + 'POST', + '/session', + $parameters, + array(CURLOPT_FOLLOWLOCATION => true) + ); + $this->capabilities = isset($result['value']['capabilities']) ? $result['value']['capabilities'] : null; $session = new Session($result['sessionUrl'], $this->capabilities); diff --git a/test/Test/WebDriver/ChromeDriverNonW3CTest.php b/test/Test/WebDriver/ChromeDriverNonW3CTest.php new file mode 100644 index 0000000..7a0de7d --- /dev/null +++ b/test/Test/WebDriver/ChromeDriverNonW3CTest.php @@ -0,0 +1,35 @@ + + */ + +namespace Test\WebDriver; + +/** + * ChromeDriver + * + * @package WebDriver + * + * @group Functional + */ +class ChromeDriverNonW3CTest extends ChromeDriverTest +{ + protected $w3c = false; +} diff --git a/test/Test/WebDriver/ChromeDriverTest.php b/test/Test/WebDriver/ChromeDriverTest.php index fde5d64..3d9bada 100644 --- a/test/Test/WebDriver/ChromeDriverTest.php +++ b/test/Test/WebDriver/ChromeDriverTest.php @@ -37,6 +37,7 @@ class ChromeDriverTest extends WebDriverTestBase { protected $testWebDriverRootUrl = 'http://localhost:9515'; protected $testWebDriverName = 'chromedriver'; + protected $w3c = true; protected $status = null; protected function setUp(): void @@ -46,7 +47,7 @@ protected function setUp(): void $this->status = $this->driver->status(); $this->session = $this->driver->session(Browser::CHROME, [ 'goog:chromeOptions' => [ - 'w3c' => true, + 'w3c' => $this->w3c, 'args' => [ '--no-sandbox', '--ignore-certificate-errors', @@ -72,5 +73,6 @@ public function testStatus() $this->assertEquals(1, $this->status['ready'], 'Chromedriver is not ready'); $this->assertEquals('ChromeDriver ready for new sessions.', $this->status['message'], 'Chromedriver is not ready'); $this->assertNotEmpty($this->status['os'], 'OS info not detected'); + $this->assertSame($this->w3c, $this->session->isW3c()); } } diff --git a/test/Test/WebDriver/Selenium4ChromeWebDriverTest.php b/test/Test/WebDriver/Selenium4ChromeWebDriverTest.php index 9f20bcb..dcf8e0f 100644 --- a/test/Test/WebDriver/Selenium4ChromeWebDriverTest.php +++ b/test/Test/WebDriver/Selenium4ChromeWebDriverTest.php @@ -25,7 +25,7 @@ protected function setUp(): void $this->status = $this->driver->status(); $this->session = $this->driver->session(Browser::CHROME, [ 'goog:chromeOptions' => [ - 'w3c' => true, + 'w3c' => $this->w3c, 'args' => [ '--no-sandbox', '--ignore-certificate-errors', diff --git a/test/Test/WebDriver/Selenium4dot8ChromeWebDriverNonW3CTest.php b/test/Test/WebDriver/Selenium4dot8ChromeWebDriverNonW3CTest.php new file mode 100644 index 0000000..651f86a --- /dev/null +++ b/test/Test/WebDriver/Selenium4dot8ChromeWebDriverNonW3CTest.php @@ -0,0 +1,17 @@ +assertEquals(1, $this->status['ready'], 'Selenium is not ready'); $this->assertEquals('Selenium Grid ready.', $this->status['message'], 'Selenium is not ready'); $this->assertNotEmpty($this->status['nodes'][0]['osInfo'], 'OS info not detected'); + $this->assertSame($this->w3c, $this->session->isW3c()); } }