From 3d43a712bccb1a4340e4b3ca7e247e70cc07c902 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 4 Jul 2024 06:46:00 +0800 Subject: [PATCH] MDL-82373 behat: Stop killing the entire Behat run on driver error If there's a driver error, for example from a step taking too long, then this kills the entire Behat run and we have to start from scratch. This change instead throws away the original connection and starts a new one to try and continue the test. --- .../Moodle/BehatExtension/Driver/WebDriver.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/behat/extension/Moodle/BehatExtension/Driver/WebDriver.php b/lib/behat/extension/Moodle/BehatExtension/Driver/WebDriver.php index 7fc601f54e0..e6c24df0937 100644 --- a/lib/behat/extension/Moodle/BehatExtension/Driver/WebDriver.php +++ b/lib/behat/extension/Moodle/BehatExtension/Driver/WebDriver.php @@ -16,6 +16,7 @@ namespace Moodle\BehatExtension\Driver; +use Behat\Mink\Exception\DriverException; use OAndreyev\Mink\Driver\WebDriver as UpstreamDriver; // phpcs:disable moodle.NamingConventions.ValidFunctionName.LowercaseMethod @@ -79,4 +80,14 @@ class WebDriver extends UpstreamDriver { public function post_key($key, $xpath) { throw new \Exception('No longer used - please use keyDown and keyUp'); } + + #[\Override] + public function stop(): void { + try { + parent::stop(); + } catch (DriverException $e) { + error_log($e->getMessage()); + $this->webDriver = null; + } + } }