From de80be59bb0bff6f230d4b0f240fb180916dbf64 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 23 Feb 2017 12:15:49 +0800 Subject: [PATCH] MDL-58056 behat: Catch webdriver exception if element removed While checking for element visibility, ensure that element is there in dom --- lib/tests/behat/behat_general.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index a6be6f4a3b8..0adb30fd263 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -624,8 +624,16 @@ class behat_general extends behat_base { function($context, $args) { foreach ($args['nodes'] as $node) { - if ($node->isVisible()) { - throw new ExpectationException('"' . $args['text'] . '" text was found in the page', $context->getSession()); + // If element is removed from dom, then just exit. + try { + // If element is visible then throw exception, so we keep spinning. + if ($node->isVisible()) { + throw new ExpectationException('"' . $args['text'] . '" text was found in the page', + $context->getSession()); + } + } catch (WebDriver\Exception\NoSuchElement $e) { + // Do nothing just return, as element is no more on page. + return true; } } @@ -637,7 +645,6 @@ class behat_general extends behat_base { false, true ); - } /**