Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix w3c false issues #10

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .ddev/docker-compose.selenium.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

@alexpott alexpott Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change to the chrome image allows ddev to work on arm laptops. selenium/standalone-chrome:latest is not available on arm... whereas selenium/standalone-chrome:4.8 is.... go figure.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect you might've already seen it, but there's this fairly recent post about multi-arch images. (Doesn't explain why it worked with 4.8, but it does speak as to why generally the chrome image doesn't support arm.)

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
Expand Down
46 changes: 21 additions & 25 deletions lib/WebDriver/WebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);

Expand Down
35 changes: 35 additions & 0 deletions test/Test/WebDriver/ChromeDriverNonW3CTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* Copyright 2021-2022 Anthon Pang. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package WebDriver
*
* @author Anthon Pang <[email protected]>
*/

namespace Test\WebDriver;

/**
* ChromeDriver
*
* @package WebDriver
*
* @group Functional
*/
class ChromeDriverNonW3CTest extends ChromeDriverTest
{
protected $w3c = false;
}
4 changes: 3 additions & 1 deletion test/Test/WebDriver/ChromeDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion test/Test/WebDriver/Selenium4ChromeWebDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
17 changes: 17 additions & 0 deletions test/Test/WebDriver/Selenium4dot8ChromeWebDriverNonW3CTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Test\WebDriver;

use WebDriver\Browser;

/**
* Selenium WebDriver
*
* @package WebDriver
*
* @group Functional
*/
class Selenium4dot8ChromeWebDriverNonW3CTest extends Selenium4dot8ChromeWebDriverTest
{
protected $w3c = FALSE;
}
17 changes: 17 additions & 0 deletions test/Test/WebDriver/Selenium4dot8ChromeWebDriverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Test\WebDriver;

use WebDriver\Browser;

/**
* Selenium WebDriver
*
* @package WebDriver
*
* @group Functional
*/
class Selenium4dot8ChromeWebDriverTest extends Selenium4ChromeWebDriverTest
{
protected $testWebDriverRootUrl = 'http://oldchrome:4444';
}
2 changes: 2 additions & 0 deletions test/Test/WebDriver/SeleniumWebDriverTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class SeleniumWebDriverTestBase extends WebDriverTestBase
protected $testWebDriverRootUrl = '';
protected $testWebDriverName = 'selenium';
protected $status = null;
protected $w3c = true;

/**
* Test driver status
Expand All @@ -23,5 +24,6 @@ public function testStatus()
$this->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());
}
}
Loading