From c9072543fc481b5741510c24a2f66a10e0201d5f Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Wed, 18 May 2016 10:35:59 +0800 Subject: [PATCH] MDL-53956 behat: Avoid before and after step and switch After pressing the button, if system is slow then after step and before step might fail as the window is closed by then. Execute steps one after other --- lib/tests/behat/behat_forms.php | 16 ++++++++++++++++ .../tests/behat/manually_mark_question.feature | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index f36571d81a9..c8ff8a057b1 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -61,6 +61,22 @@ class behat_forms extends behat_base { $buttonnode->press(); } + /** + * Press button with specified id|name|title|alt|value and switch to main window. + * + * @When /^I press "(?P(?:[^"]|\\")*)" and switch to main window$/ + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $button + */ + public function press_button_and_switch_to_main_window($button) { + // Ensures the button is present, before pressing. + $buttonnode = $this->find_button($button); + $buttonnode->press(); + + // Switch to main window. + $this->getSession()->switchToWindow(behat_general::MAIN_WINDOW_NAME); + } + /** * Fills a form with field/value data. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. * diff --git a/mod/quiz/tests/behat/manually_mark_question.feature b/mod/quiz/tests/behat/manually_mark_question.feature index eb21e19b9d6..85733384e56 100644 --- a/mod/quiz/tests/behat/manually_mark_question.feature +++ b/mod/quiz/tests/behat/manually_mark_question.feature @@ -53,8 +53,7 @@ Feature: Teachers can override the grade for any question And I press "Save" And I should see "That is not a valid number." And I set the field "Mark" to "10.0" - And I press "Save" - And I switch to the main window + And I press "Save" and switch to main window And I should see "Complete" in the "Manually graded 10 with comment: " "table_row" # This time is same as time the window is open. So wait for it to close before proceeding. And I wait "2" seconds