MDL-48624 behat: Added extended timeout to ensure step pass

following_should_download_between_and_bytes step sometimes
fails because of server speed. Added extended timout
ensuring they wait enough before failing.
Also, not calling force download while running behat site
This commit is contained in:
Rajesh Taneja
2015-01-19 10:15:47 +08:00
parent da0ef2e4cf
commit e41aa29bca
4 changed files with 34 additions and 13 deletions
+29 -2
View File
@@ -1220,7 +1220,20 @@ class behat_general extends behat_base {
* @param number $expectedsize the expected file size in bytes.
*/
public function following_should_download_bytes($link, $expectedsize) {
$result = $this->download_file_from_link($link);
$exception = new ExpectationException('Error while downloading data from ' . $link, $this->getSession());
// It will stop spinning once file is downloaded or time out.
$result = $this->spin(
function($context, $args) {
$link = $args['link'];
return $this->download_file_from_link($link);
},
array('link' => $link),
self::EXTENDED_TIMEOUT,
$exception
);
// Check download size.
$actualsize = (int)strlen($result);
if ($actualsize !== (int)$expectedsize) {
throw new ExpectationException('Downloaded data was ' . $actualsize .
@@ -1249,7 +1262,21 @@ class behat_general extends behat_base {
list($minexpectedsize, $maxexpectedsize) = array($maxexpectedsize, $minexpectedsize);
}
$result = $this->download_file_from_link($link);
$exception = new ExpectationException('Error while downloading data from ' . $link, $this->getSession());
// It will stop spinning once file is downloaded or time out.
$result = $this->spin(
function($context, $args) {
$link = $args['link'];
return $this->download_file_from_link($link);
},
array('link' => $link),
self::EXTENDED_TIMEOUT,
$exception
);
// Check download size.
$actualsize = (int)strlen($result);
if ($actualsize < $minexpectedsize || $actualsize > $maxexpectedsize) {
throw new ExpectationException('Downloaded data was ' . $actualsize .
+4 -1
View File
@@ -73,7 +73,10 @@ if ($from_form = $export_form->get_data()) {
echo get_string('yourfileshoulddownload', 'question', $export_url->out());
echo $OUTPUT->box_end();
$PAGE->requires->js_function_call('document.location.replace', array($export_url->out(false)), false, 1);
// Don't allow force download for behat site, as pop-up can't be handled by selenium.
if (!defined('BEHAT_SITE_RUNNING')) {
$PAGE->requires->js_function_call('document.location.replace', array($export_url->out(false)), false, 1);
}
echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
echo $OUTPUT->footer();
@@ -34,8 +34,4 @@ Feature: Test importing questions from GIFT format.
And I set the field "id_format_gift" to "1"
And I press "Export questions to file"
And following "click here" should download between "1550" and "1650" bytes
# If the download step is the last in the scenario then we can sometimes run
# into the situation where the download page causes a http redirect but behat
# has already conducted its reset (generating an error). By putting a logout
# step we avoid behat doing the reset until we are off that page.
And I log out
@@ -36,11 +36,6 @@ Feature: Test importing questions from Moodle XML format.
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
And following "click here" should download between "57000" and "58000" bytes
# If the download step is the last in the scenario then we can sometimes run
# into the situation where the download page causes a http redirect but behat
# has already conducted its reset (generating an error). By putting a logout
# step we avoid behat doing the reset until we are off that page.
And I log out
@javascript @_file_upload
Scenario: import some multiple choice questions from Moodle XML format