From 991c8a9e78dbea63f34316d12da33e8591e20b3c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 28 Jan 2021 14:51:29 +0800 Subject: [PATCH 1/3] MDL-66979 behat: Handle driver stop failure properly An case was found where the webdriver stop() call could fail in an AfterScenario hook, leading to a complete rerun if no other errors were experienced. --- lib/tests/behat/behat_hooks.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index d7fc9e77287..06f78785923 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -660,7 +660,24 @@ EOF; * @AfterScenario */ public function reset_webdriver_between_scenarios(AfterScenarioScope $scope) { - $this->getSession()->stop(); + try { + $this->getSession()->stop(); + } catch (Exception $e) { + $error = <<getCode(), + $e->getMessage(), + format_backtrace($e->getTrace(), true) + )); + } } /** From 230896b7a5ee8330890d086590026f9e191b8c38 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 28 Jan 2021 15:00:19 +0800 Subject: [PATCH 2/3] MDL-66979 behat: Correct selenium2 reference in config-dist --- config-dist.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config-dist.php b/config-dist.php index 336c7c607de..70464b0b26f 100644 --- a/config-dist.php +++ b/config-dist.php @@ -898,7 +898,7 @@ $CFG->admin = 'admin'; // ), // 'extensions' => array( // 'Behat\MinkExtension' => array( -// 'selenium2' => array( +// 'webddriver' => array( // 'browser' => 'firefox', // 'capabilities' => array( // 'platform' => 'OS X 10.6', @@ -911,7 +911,7 @@ $CFG->admin = 'admin'; // 'Mac-Safari' => array( // 'extensions' => array( // 'Behat\MinkExtension' => array( -// 'selenium2' => array( +// 'webddriver' => array( // 'browser' => 'safari', // 'capabilities' => array( // 'platform' => 'OS X 10.8', From 5d8e4e9fd4df31ed66f7437d5c6020e2144a94c1 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 28 Jan 2021 15:27:50 +0800 Subject: [PATCH 3/3] MDL-66979 behat: Set script timeout with timeout factor --- lib/tests/behat/behat_hooks.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 06f78785923..d2f0bea4c75 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -290,13 +290,26 @@ EOF; if ($session->isStarted()) { $session->restart(); } else { - $session->start(); + $this->start_session(); } if ($this->running_javascript() && $this->getSession()->getDriver()->getWebDriverSessionId() === 'session') { throw new DriverException('Unable to create a valid session'); } } + /** + * Start the Session, applying any initial configuratino required. + */ + protected function start_session(): void { + $this->getSession()->start(); + + $this->getSession()->getDriver()->setTimeouts([ + // The standard script timeout is 30000 ms. + // Use `get_real_timeout` to multiply this by the behat increased timeout factor. + 'script' => self::get_real_timeout(30000), + ]); + } + /** * Restart the session before each non-javascript scenario. *