MDL-39051 behat: Fix issue after closing popup windows

When a step closes a popup window the page DOM is not available
until we switch again to the main window; we should avoid exceptions
at framework level when hooking the after step process, this
includes the new exceptions catcher modification.
This commit is contained in:
David Monllao 2013-05-08 14:01:36 +08:00
parent b576bdc75d
commit 217e8e59e5

View file

@ -208,48 +208,55 @@ class behat_hooks extends behat_base {
*/ */
public function i_look_for_exceptions() { public function i_look_for_exceptions() {
// Exceptions. // Wrap in try in case we were interacting with a closed window.
if ($errormsg = $this->getSession()->getPage()->find('css', '.errorbox p.errormessage')) { try {
// Getting the debugging info and the backtrace. // Exceptions.
$errorinfoboxes = $this->getSession()->getPage()->findAll('css', 'div.notifytiny'); if ($errormsg = $this->getSession()->getPage()->find('css', '.errorbox p.errormessage')) {
$errorinfo = $this->get_debug_text($errorinfoboxes[0]->getHtml()) . "\n" .
$this->get_debug_text($errorinfoboxes[1]->getHtml());
$msg = "Moodle exception: " . $errormsg->getText() . "\n" . $errorinfo; // Getting the debugging info and the backtrace.
throw new \Exception(html_entity_decode($msg)); $errorinfoboxes = $this->getSession()->getPage()->findAll('css', 'div.notifytiny');
} $errorinfo = $this->get_debug_text($errorinfoboxes[0]->getHtml()) . "\n" .
$this->get_debug_text($errorinfoboxes[1]->getHtml());
// Debugging messages. $msg = "Moodle exception: " . $errormsg->getText() . "\n" . $errorinfo;
if ($debuggingmessages = $this->getSession()->getPage()->findAll('css', '.debuggingmessage')) { throw new \Exception(html_entity_decode($msg));
$msgs = array();
foreach ($debuggingmessages as $debuggingmessage) {
$msgs[] = $this->get_debug_text($debuggingmessage->getHtml());
} }
$msg = "debugging() message/s found:\n" . implode("\n", $msgs);
throw new \Exception(html_entity_decode($msg));
}
// PHP debug messages. // Debugging messages.
if ($phpmessages = $this->getSession()->getPage()->findAll('css', '.phpdebugmessage')) { if ($debuggingmessages = $this->getSession()->getPage()->findAll('css', '.debuggingmessage')) {
$msgs = array();
$msgs = array(); foreach ($debuggingmessages as $debuggingmessage) {
foreach ($phpmessages as $phpmessage) { $msgs[] = $this->get_debug_text($debuggingmessage->getHtml());
$msgs[] = $this->get_debug_text($phpmessage->getHtml()); }
$msg = "debugging() message/s found:\n" . implode("\n", $msgs);
throw new \Exception(html_entity_decode($msg));
} }
$msg = "PHP debug message/s found:\n" . implode("\n", $msgs);
throw new \Exception(html_entity_decode($msg));
}
// Any other backtrace. // PHP debug messages.
$backtracespattern = '/(line [0-9]* of [^:]*: call to [\->&;:a-zA-Z_\x7f-\xff][\->&;:a-zA-Z0-9_\x7f-\xff]*)/'; if ($phpmessages = $this->getSession()->getPage()->findAll('css', '.phpdebugmessage')) {
if (preg_match_all($backtracespattern, $this->getSession()->getPage()->getContent(), $backtraces)) {
$msgs = array(); $msgs = array();
foreach ($backtraces[0] as $backtrace) { foreach ($phpmessages as $phpmessage) {
$msgs[] = $backtrace . '()'; $msgs[] = $this->get_debug_text($phpmessage->getHtml());
}
$msg = "PHP debug message/s found:\n" . implode("\n", $msgs);
throw new \Exception(html_entity_decode($msg));
} }
$msg = "Other backtraces found:\n" . implode("\n", $msgs);
throw new \Exception(htmlentities($msg)); // Any other backtrace.
$backtracespattern = '/(line [0-9]* of [^:]*: call to [\->&;:a-zA-Z_\x7f-\xff][\->&;:a-zA-Z0-9_\x7f-\xff]*)/';
if (preg_match_all($backtracespattern, $this->getSession()->getPage()->getContent(), $backtraces)) {
$msgs = array();
foreach ($backtraces[0] as $backtrace) {
$msgs[] = $backtrace . '()';
}
$msg = "Other backtraces found:\n" . implode("\n", $msgs);
throw new \Exception(htmlentities($msg));
}
} catch (NoSuchWindow $e) {
// If we were interacting with a popup window it will not exists after closing it.
} }
} }