Skip to content

Commit

Permalink
Allow selenium image configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Jan 31, 2024
1 parent 0d38fd6 commit 407d392
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions src/Command/BehatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@ class BehatCommand extends AbstractMoodleCommand
{
use ExecuteTrait;

/**
* Selenium legacy Firefox image.
*/
private string $seleniumLegacyFirefoxImage = 'selenium/standalone-firefox:2.53.1';

/**
* Selenium standalone Firefox image.
*
* @todo: Make this configurable.
*/
private string $seleniumFirefoxImage = 'selenium/standalone-firefox:3';

/**
* Selenium standalone Chrome image.
*
* @todo: Make this configurable.
*/
private string $seleniumChromeImage = 'selenium/standalone-chrome:3';

/**
* Wait this many microseconds for Selenium server to start/stop.
*
Expand Down Expand Up @@ -150,13 +131,7 @@ private function startServerProcesses(InputInterface $input): void
$profile = getenv('MOODLE_BEHAT_DEFAULT_BROWSER') ?: (getenv('MOODLE_APP') ? 'chrome' : 'firefox');
}

if ($profile === 'chrome') {
$image = $this->seleniumChromeImage;
} elseif ($this->usesLegacyPhpWebdriver()) {
$image = $this->seleniumLegacyFirefoxImage;
} else {
$image = $this->seleniumFirefoxImage;
}
$image = $this->getSeleniumImage($profile);

$cmd = [
'docker',
Expand Down Expand Up @@ -226,4 +201,23 @@ private function usesLegacyPhpWebdriver(): bool

return strpos(file_get_contents($composerlock), 'instaclick/php-webdriver') !== false;
}

private function getSeleniumImage(string $profile): string
{
$image = getenv('MOODLE_BEHAT_SELENIUM_IMAGE');

if (!empty($image)) {
return $image;
}

if ($profile === 'chrome') {
return getenv('MOODLE_BEHAT_SELENIUM_CHROME_IMAGE') ?: 'selenium/standalone-chrome:3';
}

if ($this->usesLegacyPhpWebdriver()) {
return 'selenium/standalone-firefox:2.53.1';
}

return getenv('MOODLE_BEHAT_SELENIUM_FIREFOX_IMAGE') ?: 'selenium/standalone-firefox:3';
}
}

0 comments on commit 407d392

Please sign in to comment.