MDL-73070 Behat: stop using no-longer-existant classes in behat_hooks

This commit is contained in:
Tim Hunt 2021-11-12 12:01:19 +00:00
parent 7013bda35b
commit 11f8a08a0e
3 changed files with 19 additions and 22 deletions

View File

@ -123,7 +123,7 @@ class behat_form_field implements behat_session_interface {
try { try {
$instance->field->keyPress($char, $modifier); $instance->field->keyPress($char, $modifier);
$instance->field->keyUp($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 // If the JS handler attached to keydown or keypress destroys the element
// the later events may trigger errors because form element no longer exist // the later events may trigger errors because form element no longer exist
// or is not visible. Ignore such exceptions here. // or is not visible. Ignore such exceptions here.

View File

@ -27,12 +27,12 @@
require_once(__DIR__ . '/../../behat/behat_base.php'); require_once(__DIR__ . '/../../behat/behat_base.php');
use Behat\Gherkin\Node\TableNode as TableNode; use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\DriverException as DriverException; use Behat\Mink\Exception\DriverException;
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; use Behat\Mink\Exception\ElementNotFoundException;
use Behat\Mink\Exception\ExpectationException as ExpectationException; use Behat\Mink\Exception\ExpectationException;
use WebDriver\Exception\NoSuchElement as NoSuchElement; use Facebook\WebDriver\Exception\NoSuchElementException;
use WebDriver\Exception\StaleElementReference as StaleElementReference; use Facebook\WebDriver\Exception\StaleElementReferenceException;
/** /**
* Cross component steps definitions. * 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. // Wrapped in try & catch in case the redirection has already been executed.
try { try {
$content = $metarefresh->getAttribute('content'); $content = $metarefresh->getAttribute('content');
} catch (NoSuchElement $e) { } catch (NoSuchElementException $e) {
return true; return true;
} catch (StaleElementReference $e) { } catch (StaleElementReferenceException $e) {
return true; return true;
} }
@ -677,7 +677,7 @@ class behat_general extends behat_base {
throw new ExpectationException('"' . $args['text'] . '" text was found in the page', throw new ExpectationException('"' . $args['text'] . '" text was found in the page',
$context->getSession()); $context->getSession());
} }
} catch (WebDriver\Exception\NoSuchElement $e) { } catch (NoSuchElementException $e) {
// Do nothing just return, as element is no more on page. // Do nothing just return, as element is no more on page.
return true; return true;
} catch (ElementNotFoundException $e) { } catch (ElementNotFoundException $e) {

View File

@ -38,12 +38,10 @@ use Behat\Testwork\Hook\Scope\BeforeSuiteScope,
Behat\Behat\Hook\Scope\BeforeStepScope, Behat\Behat\Hook\Scope\BeforeStepScope,
Behat\Behat\Hook\Scope\AfterStepScope, Behat\Behat\Hook\Scope\AfterStepScope,
Behat\Mink\Exception\ExpectationException, Behat\Mink\Exception\ExpectationException,
Behat\Mink\Exception\DriverException as DriverException, Behat\Mink\Exception\DriverException,
WebDriver\Exception\NoSuchWindow as NoSuchWindow, Facebook\WebDriver\Exception\UnexpectedAlertOpenException,
WebDriver\Exception\UnexpectedAlertOpen as UnexpectedAlertOpen, Facebook\WebDriver\Exception\WebDriverCurlException,
WebDriver\Exception\UnknownError as UnknownError, Facebook\WebDriver\Exception\UnknownErrorException;
WebDriver\Exception\CurlExec as CurlExec,
WebDriver\Exception\NoAlertOpenError as NoAlertOpenError;
/** /**
* Hooks to the behat process. * 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() * 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. * 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; protected static $currentstepexception = null;
@ -348,17 +346,16 @@ The following debugging information is available:
EOF; EOF;
try { try {
$this->restart_session(); $this->restart_session();
} catch (CurlExec | DriverException $e) { } catch (WebDriverCurlException | DriverException $e) {
// The CurlExec Exception is thrown by WebDriver. // Thrown by WebDriver.
self::log_and_stop( self::log_and_stop(
$driverexceptionmsg . '. ' . $driverexceptionmsg . '. ' .
$e->getMessage() . "\n\n" . $e->getMessage() . "\n\n" .
format_backtrace($e->getTrace(), true) 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. // Generic 'I have no idea' Selenium error. Custom exception to provide more feedback about possible solutions.
self::log_and_stop( self::log_and_stop(
$e->getMessage() . "\n\n" . $e->getMessage() . "\n\n" .
@ -646,7 +643,7 @@ EOF;
try { try {
$this->wait_for_pending_js(); $this->wait_for_pending_js();
self::$currentstepexception = null; self::$currentstepexception = null;
} catch (UnexpectedAlertOpen $e) { } catch (UnexpectedAlertOpenException $e) {
self::$currentstepexception = $e; self::$currentstepexception = $e;
// Accepting the alert so the framework can continue properly running // Accepting the alert so the framework can continue properly running