From 015f49d0d363c710eb349d8a2fa06fe457b5353a Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Fri, 11 Apr 2014 11:14:51 +1200 Subject: [PATCH] MDL-45192 assign: added behat script & new definitions to handle alert dialog The behat script is to test the batch action to lock and unlock submissions. The new definitions are to prevent the "unexpected alert open" error in Selenium. --- lib/tests/behat/behat_forms.php | 15 +++++ lib/tests/behat/behat_general.php | 15 +++++ .../behat/prevent_submission_changes.feature | 64 ++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 42005ec9d21..c5abba2faab 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -60,6 +60,21 @@ class behat_forms extends behat_base { $buttonnode->press(); } + /** + * Presses button with specified id|name|title|alt|value, and confirming the alert dialog. + * + * @When /^I press "(?P(?:[^"]|\\")*)", confirming the dialog$/ + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $button + */ + public function press_button_confirm_dialog($button) { + + // Ensures the button is present. + $buttonnode = $this->find_button($button); + $buttonnode->press(); + $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); + } + /** * Fills a form with field/value data. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. * diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 94c677bc0d1..f86ed48b0f0 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -190,6 +190,21 @@ class behat_general extends behat_base { $linknode->click(); } + /** + * Clicks link with specified id|title|alt|text, and confirming the alert dialog. + * + * @When /^I follow "(?P(?:[^"]|\\")*)", confirming the dialog$/ + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $link + */ + public function click_link_confirm_dialog($link) { + + $linknode = $this->find_link($link); + $this->ensure_node_is_visible($linknode); + $linknode->click(); + $this->accept_currently_displayed_alert_dialog(); + } + /** * Waits X seconds. Required after an action that requires data from an AJAX request. * diff --git a/mod/assign/tests/behat/prevent_submission_changes.feature b/mod/assign/tests/behat/prevent_submission_changes.feature index ff5b8543e49..22e2d936fd4 100644 --- a/mod/assign/tests/behat/prevent_submission_changes.feature +++ b/mod/assign/tests/behat/prevent_submission_changes.feature @@ -4,8 +4,7 @@ Feature: Prevent or allow assignment submission changes As a teacher I need to prevent or allow student submission at any time - @javascript - Scenario: Preventing changes and allowing them again + Background: Given the following "courses" exists: | fullname | shortname | category | groupmode | | Course 1 | C1 | 0 | 1 | @@ -13,11 +12,16 @@ Feature: Prevent or allow assignment submission changes | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | | student1 | Student | 1 | student1@asd.com | + | student2 | Student | 2 | student2@asd.com | And the following "course enrolments" exists: | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | - And I log in as "teacher1" + | student2 | C1 | student | + + @javascript + Scenario: Preventing changes and allowing them again + Given I log in as "teacher1" And I follow "Course 1" And I turn editing mode on And I add a "Assignment" to section "1" and I fill the form with: @@ -68,3 +72,57 @@ Feature: Prevent or allow assignment submission changes | Online text | I'm the student submission edited again | And I press "Save changes" And I should see "I'm the student submission edited again" + + @javascript @_alert + Scenario: Preventing changes and allowing them again (batch action) + Given the following "activities" exist: + | activity | course | idnumber | name | intro | assignsubmission_onlinetext_enabled | assignsubmission_file_enabled | + | assign | C1 | assign1 | Test assignment name | Test assignment description | 1 | 0 | + And I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment name" + And I press "Add submission" + And I set the following fields to these values: + | Online text | I'm the student submission | + And I press "Save changes" + And I log out + And I log in as "student2" + And I follow "Course 1" + And I follow "Test assignment name" + And I press "Add submission" + And I set the following fields to these values: + | Online text | I'm the student2 submission | + And I press "Save changes" + And I log out + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Test assignment name" + When I follow "View/grade all submissions" + And I set the field "selectall" to "1" + And I press "Go", confirming the dialog + Then I should see "Submission changes not allowed" in the "Student 1" "table_row" + And I should see "Submission changes not allowed" in the "Student 2" "table_row" + And I log out + When I log in as "student2" + And I follow "Course 1" + And I follow "Test assignment name" + Then I should not see "Edit submission" + And I log out + When I log in as "teacher1" + And I follow "Course 1" + And I follow "Test assignment name" + And I follow "View/grade all submissions" + And I set the field "selectall" to "1" + And I set the field "id_operation" to "Unlock submissions" + And I press "Go", confirming the dialog + Then I should not see "Submission changes not allowed" in the "Student 1" "table_row" + And I should not see "Submission changes not allowed" in the "Student 2" "table_row" + And I log out + When I log in as "student2" + And I follow "Course 1" + And I follow "Test assignment name" + And I press "Edit submission" + And I set the following fields to these values: + | Online text | I'm the student2 submission and he/she edited me | + And I press "Save changes" + And I log out