From 11f8a08a0e45095b9fd70143da3f18c2d29d29ee Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 12 Nov 2021 12:01:19 +0000 Subject: [PATCH] MDL-73070 Behat: stop using no-longer-existant classes in behat_hooks --- lib/behat/form_field/behat_form_field.php | 2 +- lib/tests/behat/behat_general.php | 18 +++++++++--------- lib/tests/behat/behat_hooks.php | 21 +++++++++------------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/lib/behat/form_field/behat_form_field.php b/lib/behat/form_field/behat_form_field.php index 7f30d2ccab8..620b238b212 100644 --- a/lib/behat/form_field/behat_form_field.php +++ b/lib/behat/form_field/behat_form_field.php @@ -123,7 +123,7 @@ class behat_form_field implements behat_session_interface { try { $instance->field->keyPress($char, $modifier); $instance->field->keyUp($char, $modifier); - } catch (WebDriver\Exception $e) { + } catch (\Facebook\WebDriver\Exception\WebDriverException $e) { // If the JS handler attached to keydown or keypress destroys the element // the later events may trigger errors because form element no longer exist // or is not visible. Ignore such exceptions here. diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index fdd9e7432dd..42b74cec455 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -27,12 +27,12 @@ require_once(__DIR__ . '/../../behat/behat_base.php'); -use Behat\Gherkin\Node\TableNode as TableNode; -use Behat\Mink\Exception\DriverException as DriverException; -use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; -use Behat\Mink\Exception\ExpectationException as ExpectationException; -use WebDriver\Exception\NoSuchElement as NoSuchElement; -use WebDriver\Exception\StaleElementReference as StaleElementReference; +use Behat\Gherkin\Node\TableNode; +use Behat\Mink\Exception\DriverException; +use Behat\Mink\Exception\ElementNotFoundException; +use Behat\Mink\Exception\ExpectationException; +use Facebook\WebDriver\Exception\NoSuchElementException; +use Facebook\WebDriver\Exception\StaleElementReferenceException; /** * Cross component steps definitions. @@ -121,9 +121,9 @@ class behat_general extends behat_base { // Wrapped in try & catch in case the redirection has already been executed. try { $content = $metarefresh->getAttribute('content'); - } catch (NoSuchElement $e) { + } catch (NoSuchElementException $e) { return true; - } catch (StaleElementReference $e) { + } catch (StaleElementReferenceException $e) { return true; } @@ -677,7 +677,7 @@ class behat_general extends behat_base { throw new ExpectationException('"' . $args['text'] . '" text was found in the page', $context->getSession()); } - } catch (WebDriver\Exception\NoSuchElement $e) { + } catch (NoSuchElementException $e) { // Do nothing just return, as element is no more on page. return true; } catch (ElementNotFoundException $e) { diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 5458a382214..bed501645cb 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -38,12 +38,10 @@ use Behat\Testwork\Hook\Scope\BeforeSuiteScope, Behat\Behat\Hook\Scope\BeforeStepScope, Behat\Behat\Hook\Scope\AfterStepScope, Behat\Mink\Exception\ExpectationException, - Behat\Mink\Exception\DriverException as DriverException, - WebDriver\Exception\NoSuchWindow as NoSuchWindow, - WebDriver\Exception\UnexpectedAlertOpen as UnexpectedAlertOpen, - WebDriver\Exception\UnknownError as UnknownError, - WebDriver\Exception\CurlExec as CurlExec, - WebDriver\Exception\NoAlertOpenError as NoAlertOpenError; + Behat\Mink\Exception\DriverException, + Facebook\WebDriver\Exception\UnexpectedAlertOpenException, + Facebook\WebDriver\Exception\WebDriverCurlException, + Facebook\WebDriver\Exception\UnknownErrorException; /** * Hooks to the behat process. @@ -82,7 +80,7 @@ class behat_hooks extends behat_base { * failure, but we can store them here to fail the step in i_look_for_exceptions() * which result will be parsed by the framework as the last step result. * - * @var Null or the exception last step throw in the before or after hook. + * @var ?Exception Null or the exception last step throw in the before or after hook. */ protected static $currentstepexception = null; @@ -348,17 +346,16 @@ The following debugging information is available: EOF; - try { $this->restart_session(); - } catch (CurlExec | DriverException $e) { - // The CurlExec Exception is thrown by WebDriver. + } catch (WebDriverCurlException | DriverException $e) { + // Thrown by WebDriver. self::log_and_stop( $driverexceptionmsg . '. ' . $e->getMessage() . "\n\n" . format_backtrace($e->getTrace(), true) ); - } catch (UnknownError $e) { + } catch (UnknownErrorException $e) { // Generic 'I have no idea' Selenium error. Custom exception to provide more feedback about possible solutions. self::log_and_stop( $e->getMessage() . "\n\n" . @@ -646,7 +643,7 @@ EOF; try { $this->wait_for_pending_js(); self::$currentstepexception = null; - } catch (UnexpectedAlertOpen $e) { + } catch (UnexpectedAlertOpenException $e) { self::$currentstepexception = $e; // Accepting the alert so the framework can continue properly running