// Wrapped in a try & catch as we can fall into race conditions
// and the element may not be there.
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();
} catch (Exception $e) {
// We continue and return as this means that the element is not there or it is not the same.
}
} 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
// and the element may not be there.
try {
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
// and the element may not be there.
try {
/**
* Waits for all the JS to be loaded.
*
+ * @throws \Exception
* @throws NoSuchWindow
* @throws UnknownError
* @return bool True or false depending whether all the JS is loaded or not.
usleep(100000);
}
- // Timeout waiting for JS to complete.
- // TODO MDL-43173 We should fail the scenarios if JS loading times out.
- return false;
+ // Timeout waiting for JS to complete. It will be catched and forwarded to behat_hooks::i_look_for_exceptions().
+ // It is unlikely that Javascript code of a page or an AJAX request needs more than self::EXTENDED_TIMEOUT seconds
+ // 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.');
}
/**