Browse files

Merge branch 'MDL-39528_25' of git://github.com/dmonllao/moodle into …

…MOODLE_25_STABLE
  • Loading branch information...
2 parents 1cdcb65 + 236ebcf commit c4500213d67ec4286be250e58ba995d67bc7ce84 @damyon damyon committed May 20, 2013
Showing with 20 additions and 1 deletion.
  1. +20 −1 lib/tests/behat/behat_hooks.php
View
21 lib/tests/behat/behat_hooks.php
@@ -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.
@@ -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.
+ }
+ }
+
}
/**
@@ -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.');
}
}

0 comments on commit c450021

Please sign in to comment.