Merge branch 'MDL-43173_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Dan Poltawski 2014-01-08 08:21:06 +08:00
commit 267d4927b4
2 changed files with 21 additions and 3 deletions

View file

@ -104,6 +104,11 @@ class behat_form_select extends behat_form_field {
// Wrapped in a try & catch as we can fall into race conditions // Wrapped in a try & catch as we can fall into race conditions
// and the element may not be there. // and the element may not be there.
try { try {
// Wait for all the possible AJAX requests that have been
// already triggered by selectOption() to be finished.
$this->session->wait(behat_base::TIMEOUT * 1000, behat_base::PAGE_READY_JS);
current($optionnodes)->click(); current($optionnodes)->click();
} catch (Exception $e) { } catch (Exception $e) {
// We continue and return as this means that the element is not there or it is not the same. // We continue and return as this means that the element is not there or it is not the same.
@ -112,6 +117,11 @@ class behat_form_select extends behat_form_field {
} }
} else { } else {
// Wait for all the possible AJAX requests that have been
// already triggered by selectOption() to be finished.
$this->session->wait(behat_base::TIMEOUT * 1000, behat_base::PAGE_READY_JS);
// Wrapped in a try & catch as we can fall into race conditions // Wrapped in a try & catch as we can fall into race conditions
// and the element may not be there. // and the element may not be there.
try { try {
@ -127,6 +137,10 @@ class behat_form_select extends behat_form_field {
return; return;
} }
// Wait for all the possible AJAX requests that have been
// already triggered by selectOption() to be finished.
$this->session->wait(behat_base::TIMEOUT * 1000, behat_base::PAGE_READY_JS);
// Wrapped in a try & catch as we can fall into race conditions // Wrapped in a try & catch as we can fall into race conditions
// and the element may not be there. // and the element may not be there.
try { try {

View file

@ -281,6 +281,7 @@ class behat_hooks extends behat_base {
/** /**
* Waits for all the JS to be loaded. * Waits for all the JS to be loaded.
* *
* @throws \Exception
* @throws NoSuchWindow * @throws NoSuchWindow
* @throws UnknownError * @throws UnknownError
* @return bool True or false depending whether all the JS is loaded or not. * @return bool True or false depending whether all the JS is loaded or not.
@ -314,9 +315,12 @@ class behat_hooks extends behat_base {
usleep(100000); usleep(100000);
} }
// Timeout waiting for JS to complete. // Timeout waiting for JS to complete. It will be catched and forwarded to behat_hooks::i_look_for_exceptions().
// TODO MDL-43173 We should fail the scenarios if JS loading times out. // It is unlikely that Javascript code of a page or an AJAX request needs more than self::EXTENDED_TIMEOUT seconds
return false; // to be loaded, although when pages contains Javascript errors M.util.js_complete() can not be executed, so the
// number of JS pending code and JS completed code will not match and we will reach this point.
throw new \Exception('Javascript code and/or AJAX requests are not ready after ' . self::EXTENDED_TIMEOUT .
' seconds. There is a Javascript error or the code is extremely slow.');
} }
/** /**