Commit 775b9a36 authored by Andrew Nicols's avatar Andrew Nicols
Browse files

MDL-69232 behat: Make selenium start more fault tolerant

The session was previously only started once, but has now been moved to
restart between each test. Because of this the `$session->start()` is
now called more frequently which exposes a pre-existing issue whereby
Selenium will periodically fail to start.

When the session was only started at the beginning of the test, and at
occasional other times, it made sense to always stop the test runner
because it signified an issue with obtaining the session at all.

Since the session is restarted more frequently, and now between every
test, it no longer makes sense to do this. The test should only be
_stopped_ if the first attempt to obtain the Session fails. Once a
Session has been retrieved at least once it no longer makes sense to
assume that the failure was a configuration failure, but a connection
failure. Therefore subsequent tests should be attempted.
parent f216c901
......@@ -293,6 +293,21 @@ class behat_hooks extends behat_base {
* Helper function to restart the Mink session.
protected function restart_session(): void {
$session = $this->getSession();
if ($session->isStarted()) {
} else {
if ($this->running_javascript() && $this->getSession()->getDriver()->getWebDriverSessionId() === 'session') {
throw new DriverException('Unable to create valid session');
* Resets the test environment.
......@@ -302,10 +317,14 @@ class behat_hooks extends behat_base {
public function before_scenario(BeforeScenarioScope $scope) {
global $DB, $CFG;
if (self::$initprocessesfinished) {
} else {
$moreinfo = 'More info in ' . behat_command::DOCS_URL;
$driverexceptionmsg = 'Selenium server is not running, you need to start it to run tests that involve Javascript. ' . $moreinfo;
try {
$session = $this->getSession();
} catch (CurlExec $e) {
// Exception thrown by WebDriver, so only @javascript tests will be caugth; in
// behat_util::check_server_status() we already checked that the server is running.
......@@ -327,6 +346,7 @@ class behat_hooks extends behat_base {
format_backtrace($e->getTrace(), true)
$suitename = $scope->getSuite()->getName();
......@@ -361,9 +381,6 @@ class behat_hooks extends behat_base {
// Reset mink session between the scenarios.
// Reset $SESSION.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment