MDL-40033 behat: Waiting until file manager is available

This commit is contained in:
David Monllao 2013-06-18 10:50:44 +08:00
parent 0ea1fbbb55
commit 50eeae5906
4 changed files with 117 additions and 22 deletions

View File

@ -31,7 +31,8 @@
require_once(__DIR__ . '/behat_base.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException;
use Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/**
* Files-related actions.
@ -187,4 +188,55 @@ class behat_files extends behat_base {
// Selecting the repo.
$repositorylink->click();
}
/**
* Waits until the file manager modal windows are closed.
*
* @throws ExpectationException
* @return void
*/
protected function wait_until_return_to_form() {
$exception = new ExpectationException('The file manager is taking too much time to finish the current action', $this->getSession());
$this->find(
'xpath',
"//div[@id='filesskin']" .
"/descendant::div[contains(concat(' ', @class, ' '), ' yui3-widget-mask ')]" .
"[contains(concat(' ', @style, ' '), ' display: none; ')]",
$exception
);
}
/**
* Checks that the file manager contents are not being updated.
*
* @throws ExpectationException
* @param NodeElement $filepickernode The file manager DOM node
* @return void
*/
protected function wait_until_contents_are_updated($filepickernode) {
$exception = new ExpectationException(
'The file manager contents are requiring too much time to be updated',
$this->getSession()
);
// Looks for the loading image not being displayed. For single-file filepickers is
// only used when accessing the filepicker, there is no filemanager-loading after selecting the file.
$this->find(
'xpath',
"//div[contains(concat(' ', @class, ' '), ' filemanager ')]" .
"[not(contains(concat(' ', @class, ' '), ' fm-updating '))]" .
"|" .
"//div[contains(concat(' ', @class, ' '), ' filemanager-loading ')]" .
"[contains(@style, 'display: none;')]",
$exception,
$filepickernode
);
// After removing the class FileManagerHelper.view_files() performs other actions.
$this->getSession()->wait(4 * 1000, false);
}
}

View File

@ -58,8 +58,11 @@ class behat_repository_recent extends behat_files {
$this->find_button('Select this file')->click();
// Wait a while for the file to be selected.
$this->getSession()->wait(3 * 1000, false);
// Ensure the file has been selected and we returned to the form page.
$this->wait_until_return_to_form();
// Wait until file manager contents are updated.
$this->wait_until_contents_are_updated($filepickernode);
}
}

View File

@ -65,8 +65,11 @@ class behat_filepicker extends behat_files {
$this->getSession()->getPage()->pressButton('Create folder');
// Wait few seconds for the folder to be created and filepicker contents reloaded.
$this->getSession()->wait(4 * 1000, false);
// Wait until the process finished and modal windows are hidden.
$this->wait_until_return_to_form();
// Wait until the current folder contents are updated
$this->wait_until_contents_are_updated($fieldnode);
}
/**
@ -86,6 +89,9 @@ class behat_filepicker extends behat_files {
$this->getSession()
);
// Just in case there is any contents refresh in progress.
$this->wait_until_contents_are_updated($fieldnode);
// We look both in the pathbar and in the contents.
try {
@ -93,7 +99,8 @@ class behat_filepicker extends behat_files {
$folder = $this->find(
'xpath',
"//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]" .
"//descendant::div[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]",
"/descendant::div[contains(concat(' ', @class, ' '), ' fp-filename ')]" .
"[normalize-space(.)='" . $foldername . "']",
$exception,
$fieldnode
);
@ -103,7 +110,7 @@ class behat_filepicker extends behat_files {
$folder = $this->find(
'xpath',
"//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-path-folder-name ')]" .
"[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]",
"[normalize-space(.)='" . $foldername . "']",
$exception,
$fieldnode
);
@ -112,8 +119,8 @@ class behat_filepicker extends behat_files {
// It should be a NodeElement, otherwise an exception would have been thrown.
$folder->click();
// Wait few seconds for the filepicker contents to be updated.
$this->getSession()->wait(4 * 1000, false);
// Wait until the current folder contents are updated
$this->wait_until_contents_are_updated($fieldnode);
}
/**
@ -133,9 +140,12 @@ class behat_filepicker extends behat_files {
$exception = new ExpectationException($filename.' element can not be unzipped', $this->getSession());
$this->perform_on_element('unzip', $exception);
// Wait few seconds.
// Here the time will depend on the zip contents and the server load, so it better to be conservative.
$this->getSession()->wait(8 * 1000, false);
// Wait until the process finished and modal windows are hidden.
$this->wait_until_return_to_form();
// Wait until the current folder contents are updated
$containernode = $this->get_filepicker_node($filepickerelement);
$this->wait_until_contents_are_updated($containernode);
}
/**
@ -155,9 +165,12 @@ class behat_filepicker extends behat_files {
$exception = new ExpectationException($foldername.' element can not be zipped', $this->getSession());
$this->perform_on_element('zip', $exception);
// Wait few seconds.
// Here the time will depend on the folder contents and the server load, so it better to be conservative.
$this->getSession()->wait(8 * 1000, false);
// Wait until the process finished and modal windows are hidden.
$this->wait_until_return_to_form();
// Wait until the current folder contents are updated
$containernode = $this->get_filepicker_node($filepickerelement);
$this->wait_until_contents_are_updated($containernode);
}
/**
@ -182,8 +195,12 @@ class behat_filepicker extends behat_files {
$okbutton = $this->find('css', 'div.fp-dlg button.fp-dlg-butconfirm');
$okbutton->click();
// Wait few seconds until filepicker contents are reloaded.
$this->getSession()->wait(4 * 1000, false);
// Wait until the process finished and modal windows are hidden.
$this->wait_until_return_to_form();
// Wait until file manager contents are updated.
$containernode = $this->get_filepicker_node($filepickerelement);
$this->wait_until_contents_are_updated($containernode);
}
}

View File

@ -54,20 +54,43 @@ class behat_repository_upload extends behat_files {
$filepickernode = $this->get_filepicker_node($filepickerelement);
// Wait until file manager is completely loaded.
$this->wait_until_contents_are_updated($filepickernode);
// Opening the select repository window and selecting the upload repository.
$this->open_add_file_window($filepickernode, get_string('pluginname', 'repository_upload'));
// Ensure all the form is ready.
$this->getSession()->wait(2 * 1000, false);
$noformexception = new ExpectationException('The upload file form is not ready', $this->getSession());
$this->find(
'xpath',
"//div[contains(concat(' ', @class, ' '), ' file-picker ')]" .
"[contains(concat(' ', @class, ' '), ' repository_upload ')]" .
"/descendant::div[@class='fp-content']" .
"/descendant::div[contains(concat(' ', @class, ' '), ' fp-upload-form ')]" .
"/descendant::form",
$noformexception
);
// After this we have the elements we want to interact with.
// Form elements to interact with.
$file = $this->find_file('repo_upload_file');
$submit = $this->find_button(get_string('upload', 'repository'));
// Attaching specified file to the node.
$filepath = str_replace('/', DIRECTORY_SEPARATOR, $filepath);
$fileabsolutepath = $CFG->dirroot . DIRECTORY_SEPARATOR . $filepath;
$inputfilenode = $this->find_file('repo_upload_file');
$inputfilenode->attachFile($fileabsolutepath);
$file->attachFile($fileabsolutepath);
// Submit the file.
$this->getSession()->getPage()->pressButton('Upload this file');
$submit->press();
// Wait a while for the file to be uploaded.
$this->getSession()->wait(6 * 1000, false);
// Ensure the file has been uploaded and all ajax processes finished.
$this->wait_until_return_to_form();
// Wait until file manager contents are updated.
$this->wait_until_contents_are_updated($filepickernode);
}
}