MDL-41030 Behat: Add support for waiting for javascript

This is so that phantomjs (which runs faster than selenium) can pass the tests.
This commit is contained in:
Damyon Wiese
2013-12-06 12:13:39 +08:00
committed by David Monllao
parent 5d2b67228c
commit 6e2c417c1f
4 changed files with 124 additions and 34 deletions
+9 -3
View File
@@ -1043,14 +1043,18 @@ class page_requirements_manager {
public function js_init_code($jscode, $ondomready = false, array $module = null) {
$jscode = trim($jscode, " ;\n"). ';';
$uniqid = html_writer::random_id();
$startjs = " M.util.js_pending('" . $uniqid . "');";
$endjs = " M.util.js_complete('" . $uniqid . "');";
if ($module) {
$this->js_module($module);
$modulename = $module['name'];
$jscode = "Y.use('$modulename', function(Y) { $jscode });";
$jscode = "$startjs Y.use('$modulename', function(Y) { $jscode $endjs });";
}
if ($ondomready) {
$jscode = "Y.on('domready', function() { $jscode });";
$jscode = "$startjs Y.on('domready', function() { $jscode $endjs });";
}
$this->jsinitcode[] = $jscode;
@@ -1216,7 +1220,7 @@ class page_requirements_manager {
$output .= js_writer::function_call($data[0], $data[1], $data[2]);
}
if (!empty($ondomready)) {
$output = " Y.on('domready', function() {\n$output\n });";
$output = " Y.on('domready', function() {\n$output\n});";
}
}
return $output;
@@ -1463,6 +1467,8 @@ class page_requirements_manager {
// Add other requested modules.
$output = $this->get_extra_modules_code();
$this->js_init_code('M.util.js_complete("init");', true);
// All the other linked scripts - there should be as few as possible.
if ($this->jsincludes['footer']) {
foreach ($this->jsincludes['footer'] as $url) {