Skip to content

Commit

Permalink
Merge branch 'MDL-39528_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed May 20, 2013
2 parents 2f75633 + 870349e commit e8dc568
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/tests/behat/behat_hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
use Behat\Behat\Event\SuiteEvent as SuiteEvent,
Behat\Behat\Event\ScenarioEvent as ScenarioEvent,
Behat\Behat\Event\StepEvent as StepEvent,
WebDriver\Exception\NoSuchWindow as NoSuchWindow;
WebDriver\Exception\NoSuchWindow as NoSuchWindow,
WebDriver\Exception\UnexpectedAlertOpen as UnexpectedAlertOpen,
WebDriver\Exception\NoAlertOpenError as NoAlertOpenError;

/**
* Hooks to the behat process.
Expand Down Expand Up @@ -138,6 +140,16 @@ public function before_scenario($event) {

// Start always in the the homepage.
$this->getSession()->visit($this->locate_path('/'));

// Closing JS dialogs if present. Otherwise they would block this scenario execution.
if ($this->running_javascript()) {
try {
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
} catch (NoAlertOpenError $e) {
// All ok, there should not be JS dialogs in theory.
}
}

}

/**
Expand Down Expand Up @@ -257,6 +269,13 @@ public function i_look_for_exceptions() {

} catch (NoSuchWindow $e) {
// If we were interacting with a popup window it will not exists after closing it.
} catch (UnexpectedAlertOpen $e) {
// We fail the scenario if we find an opened JS alert/confirm, in most of the cases it
// will be there because we are leaving an edited form without submitting/cancelling
// it, but moodle is using JS confirms and we can not just cancel the JS dialog
// as in some cases (delete activity with JS enabled for example) the test writer should
// use extra steps to deal with moodle's behaviour.
throw new Exception('Modal window present. Ensure there are no edited forms pending to submit/cancel.');
}
}

Expand Down

0 comments on commit e8dc568

Please sign in to comment.