Skip to content

Commit

Permalink
Allow selenium image configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin authored and stronk7 committed Feb 5, 2024
1 parent 8124fe7 commit f7ec3d1
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);

Check warning on line 134 in src/Command/BehatCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BehatCommand.php#L134

Added line #L134 was not covered by tests

$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

Check warning on line 205 in src/Command/BehatCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BehatCommand.php#L205

Added line #L205 was not covered by tests
{
$image = getenv('MOODLE_BEHAT_SELENIUM_IMAGE');

Check warning on line 207 in src/Command/BehatCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BehatCommand.php#L207

Added line #L207 was not covered by tests

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

Check warning on line 210 in src/Command/BehatCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BehatCommand.php#L209-L210

Added lines #L209 - L210 were not covered by tests
}

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

Check warning on line 214 in src/Command/BehatCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BehatCommand.php#L213-L214

Added lines #L213 - L214 were not covered by tests
}

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

Check warning on line 218 in src/Command/BehatCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BehatCommand.php#L217-L218

Added lines #L217 - L218 were not covered by tests
}

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

Check warning on line 221 in src/Command/BehatCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BehatCommand.php#L221

Added line #L221 was not covered by tests
}
}

0 comments on commit f7ec3d1

Please sign in to comment.