Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Nov 4, 2024
1 parent 90e86d6 commit afd8e2a
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions tests/WebdriverClassicConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,43 @@ public function createDriver(): WebdriverClassicDriver
{
$seleniumHost = $_SERVER['DRIVER_URL'];

// TODO This is temporary until we have first-class support for switching to headless mode
$capabilities = [];
if ($this->isChrome() && !$this->isHeaded()) {
$capabilities = [
'goog:chromeOptions' => [
'excludeSwitches' => ['enable-automation'],
'args' => [
'no-first-run',
'no-default-browser-check',
'disable-dev-shm-usage',
'ignore-certificate-errors',
'window-size=1050,720',
'disable-gpu',
'headless=new',
return new WebdriverClassicDriver(
$this->getBrowserName(),
// TODO This is temporary until we have first-class support for switching to headless mode
$this->isHeaded() ? [] : $this->getHeadlessCapabilities(),
$seleniumHost
);
}

private function getHeadlessCapabilities(): array
{
switch ($browser = getenv('WEB_FIXTURES_BROWSER')) {
case 'chrome':
return [
'goog:chromeOptions' => [
'excludeSwitches' => ['enable-automation'],
'args' => [
'no-first-run',
'no-default-browser-check',
'disable-dev-shm-usage',
'disable-gpu',
'headless=new',
],
],
],
];
}
];

case 'firefox':
return [
'moz:firefoxOptions' => [
'args' => [
'-headless',
],
],
];

return new WebdriverClassicDriver($this->getBrowserName(), $capabilities, $seleniumHost);
default:
throw new \RuntimeException("Cannot get headless capabilities of unsupported browser: $browser");
}
}

public function getBrowserName(): string
Expand Down Expand Up @@ -99,17 +116,13 @@ private function isXvfb(): bool

private function isHeaded(): bool
{
return filter_var(getenv('HEADED'), FILTER_VALIDATE_BOOLEAN);
}

private function isChrome(): bool
{
return getenv('WEB_FIXTURES_BROWSER') === 'chrome';
$headed = getenv('HEADED');
return filter_var($headed !== false ? $headed : 'true', FILTER_VALIDATE_BOOLEAN);
}

private function isOldChrome(): bool
{
return $this->isChrome()
return getenv('WEB_FIXTURES_BROWSER') === 'chrome'
&& version_compare(getenv('SELENIUM_VERSION') ?: '', '3', '<');
}
}

0 comments on commit afd8e2a

Please sign in to comment.