From bda1dea4de34833af2aa1c52feba0fce5a9dc312 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 8 Jul 2013 10:58:30 +0200 Subject: [PATCH] MDL-40562 behat: Catch NoSuchElement exception --- lib/tests/behat/behat_general.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index db0e2261d63..f15e5f66d61 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -29,7 +29,8 @@ require_once(__DIR__ . '/../../behat/behat_base.php'); use Behat\Mink\Exception\ExpectationException as ExpectationException, Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException, - Behat\Mink\Exception\DriverException as DriverException; + Behat\Mink\Exception\DriverException as DriverException, + WebDriver\Exception\NoSuchElement as NoSuchElement; /** * Cross component steps definitions. @@ -78,10 +79,17 @@ class behat_general extends behat_base { return false; } - $content = $metarefresh->getAttribute('content'); + // Wrapped in try & catch in case the redirection has already been executed. + try { + $content = $metarefresh->getAttribute('content'); + } catch (NoSuchElement $e) { + return false; + } + + // Getting the refresh time and the url if present. if (strstr($content, 'url') != false) { - list($waittime, $url) = explode(';', $metarefresh->getAttribute('content')); + list($waittime, $url) = explode(';', $content); // Cleaning the URL value. $url = trim(substr($url, strpos($url, 'http')));