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.
This commit is contained in:
Andrew Nicols
2014-12-04 12:59:06 +01:00
committed by Eloy Lafuente (stronk7)
parent fba1d33198
commit aa39908cef
+17
View File
@@ -63,6 +63,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 = null;
/**
* Opens Moodle 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;
}
/**