From 407d392a49fd2409709b14f04553ab5c26716632 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 31 Jan 2024 14:33:31 +0100 Subject: [PATCH] Allow selenium image configuration --- src/Command/BehatCommand.php | 46 ++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/Command/BehatCommand.php b/src/Command/BehatCommand.php index 3da0074f..c5a081c8 100644 --- a/src/Command/BehatCommand.php +++ b/src/Command/BehatCommand.php @@ -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. * @@ -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', @@ -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'; + } }