From cb8c8a2fbafaebda177f6b66be21fa0af7864518 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Wed, 14 Jan 2015 09:33:38 +0800 Subject: [PATCH] MDL-48624 behat: Added extended timeout in workshop step i_allocate_submissions_in_workshop_as step sometimes fails because of server speed. Added extended timout ensuring they wait enough before failing. --- .../behat/behat_workshopallocation_manual.php | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php b/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php index 18579cbf806..99b861374e4 100644 --- a/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php +++ b/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php @@ -51,32 +51,40 @@ class behat_workshopallocation_manual extends behat_base { * @param string $participantname */ public function i_add_a_reviewer_for_workshop_participant($reviewername, $participantname) { - $participantnameliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($participantname); - $xpathtd = "//table[contains(concat(' ', normalize-space(@class), ' '), ' allocations ')]/". - "tbody/tr[./td[contains(concat(' ', normalize-space(@class), ' '), ' peer ')]". - "[contains(.,$participantnameliteral)]]/". - "td[contains(concat(' ', normalize-space(@class), ' '), ' reviewedby ')]"; - $xpathselect = $xpathtd . "/descendant::select"; - try { - $selectnode = $this->find('xpath', $xpathselect); - } catch (Exception $ex) { - $this->find_button(get_string('showallparticipants', 'workshopallocation_manual'))->press(); - $selectnode = $this->find('xpath', $xpathselect); - } - $selectid = $selectnode->getAttribute('id'); - $selectformfield = behat_field_manager::get_form_field($selectnode, $this->getSession()); - $selectformfield->set_value($reviewername); + // It will stop spinning once all reviewer for workshop participants are added or it time out. + $this->spin( + function($context, $args) { + $participantnameliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($args['participantname']); + $xpathtd = "//table[contains(concat(' ', normalize-space(@class), ' '), ' allocations ')]/". + "tbody/tr[./td[contains(concat(' ', normalize-space(@class), ' '), ' peer ')]". + "[contains(.,$participantnameliteral)]]/". + "td[contains(concat(' ', normalize-space(@class), ' '), ' reviewedby ')]"; + $xpathselect = $xpathtd . "/descendant::select"; + try { + $selectnode = $this->find('xpath', $xpathselect); + } catch (Exception $ex) { + $this->find_button(get_string('showallparticipants', 'workshopallocation_manual'))->press(); + $selectnode = $this->find('xpath', $xpathselect); + } - if (!$this->running_javascript()) { - // Without Javascript we need to press the "Go" button. - $go = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('go')); - $this->find('xpath', $xpathtd."/descendant::input[@value=$go]")->click(); - } else { - // With Javascript we just wait for the page to reload and the success string to appear. - $allocatedtext = $this->getSession()->getSelectorsHandler()->xpathLiteral( - get_string('allocationadded', 'workshopallocation_manual')); - $this->find('xpath', "//*[contains(.,$allocatedtext)]"); - } + $selectformfield = behat_field_manager::get_form_field($selectnode, $this->getSession()); + $selectformfield->set_value($args['reviewername']); + + if (!$this->running_javascript()) { + // Without Javascript we need to press the "Go" button. + $go = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('go')); + $this->find('xpath', $xpathtd."/descendant::input[@value=$go]")->click(); + } else { + // With Javascript we just wait for the page to reload and the success string to appear. + $allocatedtext = $this->getSession()->getSelectorsHandler()->xpathLiteral( + get_string('allocationadded', 'workshopallocation_manual')); + $this->find('xpath', "//*[contains(.,$allocatedtext)]"); + } + return true; + }, + array('participantname' => $participantname, 'reviewername' => $reviewername), + self::EXTENDED_TIMEOUT + ); } /**