* @var $pageloaddetectionrunning boolean Used to ensure that page load detection was started before a page reload
* was checked for.
*/
- private $pageloaddetectionrunning = null;
+ private $pageloaddetectionrunning = false;
/**
* Opens Moodle homepage.
throw new DriverException('Page load detection requires JavaScript.');
}
- if ($this->getSession()->getPage()->find('xpath', $this->get_page_load_xpath())) {
+ $session = $this->getSession();
+
+ if ($this->pageloaddetectionrunning || $session->getPage()->find('xpath', $this->get_page_load_xpath())) {
// If we find this node at this point we are already watching for a reload and the behat steps
// are out of order. We will treat this as an error - really it needs to be fixed as it indicates a problem.
- throw new ExpectationException('Page load expectation error: page reloads are already been watched for.');
+ throw new ExpectationException(
+ 'Page load expectation error: page reloads are already been watched for.', $session);
}
$this->pageloaddetectionrunning = true;
- $this->getSession()->evaluateScript(
+ $session->evaluateScript(
'var span = document.createElement("span");
span.setAttribute("data-rel", "' . self::PAGE_LOAD_DETECTION_STRING . '");
span.setAttribute("style", "display: none;");
* @Given /^a new page should have loaded since I started watching$/
*/
public function a_new_page_should_have_loaded_since_i_started_watching() {
- // As the node is inserted by code above it is either there or not, and we do not need spin and it is safe
- // to use the native API here which is great as exception handling (the alternative is slow).
- if ($this->getSession()->getPage()->find('xpath', $this->get_page_load_xpath())) {
- // We don't want to find this node, if we do we have an error.
+ $session = $this->getSession();
+
+ // Make sure page load tracking was started.
+ if (!$this->pageloaddetectionrunning) {
throw new ExpectationException(
- 'Page load expectation error: a new page has not been loaded when it should have been.',
- $this->getSession()
- );
+ 'Page load expectation error: page load tracking was not started.', $session);
}
- if (!$this->pageloaddetectionrunning) {
+ // As the node is inserted by code above it is either there or not, and we do not need spin and it is safe
+ // to use the native API here which is great as exception handling (the alternative is slow).
+ if ($session->getPage()->find('xpath', $this->get_page_load_xpath())) {
+ // We don't want to find this node, if we do we have an error.
throw new ExpectationException(
- 'Page load expectation error: page load tracking was not started.',
- $this->getSession());
+ 'Page load expectation error: a new page has not been loaded when it should have been.', $session);
}
- // Cancel the trakcing of pageloaddetectionrunning.
+ // Cancel the tracking of pageloaddetectionrunning.
$this->pageloaddetectionrunning = false;
}
* @Given /^a new page should not have loaded since I started watching$/
*/
public function a_new_page_should_not_have_loaded_since_i_started_watching() {
+ // Make sure page load tracking was started.
+ if (!$this->pageloaddetectionrunning) {
+ throw new ExpectationException(
+ 'Page load expectation error: page load tracking was not started.', $session);
+ }
+
// We use our API here as we can use the exception handling provided by it.
$this->find(
'xpath',