From 2765175cf7904a8617325c2d781c44bf61e23966 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 2 Dec 2014 08:57:38 +0800 Subject: [PATCH] MDL-48374 behat: improved page load detection Check that page load detection was correctly started before testing that a new page was loaded. Without this, it is possible to have mutliple subsequent cases of: And a new page should have loaded since I started watching Without first starting the page load detection. --- lib/tests/behat/behat_general.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index b4e4465..eb9bc67 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -64,6 +64,12 @@ class behat_general extends behat_base { const PAGE_LOAD_DETECTION_STRING = 'new_page_not_loaded_since_behat_started_watching'; /** + * @var $pageloaddetectionrunning boolean Used to ensure that page load detection was started before a page reload + * was checked for. + */ + private $pageloaddetectionrunning = false; + + /** * Opens Moodle homepage. * * @Given /^I am on homepage$/ @@ -1246,6 +1252,8 @@ class behat_general extends behat_base { throw new ExpectationException('Page load expectation error: page reloads are already been watched for.'); } + $this->pageloaddetectionrunning = true; + $this->getSession()->evaluateScript( 'var span = document.createElement("span"); span.setAttribute("data-rel", "' . self::PAGE_LOAD_DETECTION_STRING . '"); @@ -1269,6 +1277,15 @@ class behat_general extends behat_base { $this->getSession() ); } + + if (!$this->pageloaddetectionrunning) { + throw new ExpectationException( + 'Page load expectation error: page load tracking was not started.', + $this->getSession()); + } + + // Cancel the trakcing of pageloaddetectionrunning. + $this->pageloaddetectionrunning = false; } /** -- 2.1.2