From 955118d831c31df145d238a68758009406c062cd Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 24 Jun 2014 16:53:11 +0800 Subject: [PATCH 1/4] MDL-43835 behat: Fixed matches for select form field --- completion/tests/behat/restrict_activity_by_grade.feature | 2 +- completion/tests/behat/restrict_section_availability.feature | 2 +- grade/tests/behat/grade_point_maximum.feature | 4 ++-- lib/behat/form_field/behat_form_select.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/completion/tests/behat/restrict_activity_by_grade.feature b/completion/tests/behat/restrict_activity_by_grade.feature index 441c81b352d..fa9b9099f00 100644 --- a/completion/tests/behat/restrict_activity_by_grade.feature +++ b/completion/tests/behat/restrict_activity_by_grade.feature @@ -39,7 +39,7 @@ Feature: Restrict activity availability through grade conditions | Name | Test page name | | Description | Restricted page, till grades in Grade assignment is at least 20% | | Page content | Test page contents | - | id | 2 | + | id | Grade assignment | | minval | 20 | And I press "Save and return to course" And I log out diff --git a/completion/tests/behat/restrict_section_availability.feature b/completion/tests/behat/restrict_section_availability.feature index 80858db4931..584506af859 100644 --- a/completion/tests/behat/restrict_section_availability.feature +++ b/completion/tests/behat/restrict_section_availability.feature @@ -75,7 +75,7 @@ Feature: Restrict sections availability through completion or grade conditions And I click on "Grade" "button" in the "Add restriction..." "dialogue" And I click on "min" "checkbox" And I set the following fields to these values: - | id | 2 | + | id | Grade assignment | | minval | 20 | And I press "Save changes" And I log out diff --git a/grade/tests/behat/grade_point_maximum.feature b/grade/tests/behat/grade_point_maximum.feature index 72e559731ed..7aa6e00a7f0 100644 --- a/grade/tests/behat/grade_point_maximum.feature +++ b/grade/tests/behat/grade_point_maximum.feature @@ -57,10 +57,10 @@ Feature: We can change the grading type and maximum grade point values And I follow "Edit settings" And I expand all fieldsets And I set the field "grade[modgrade_type]" to "Scale" - And I set the field "grade[modgrade_scale]" to "1" + And I set the field "grade[modgrade_scale]" to "Separate and Connected ways of knowing" And I press "Save and display" And I follow "Edit settings" - Then the field "grade[modgrade_scale]" matches value "1" + Then the field "grade[modgrade_scale]" matches value "Separate and Connected ways of knowing" And the "Maximum points" "field" should be disabled And I press "Save and return to course" diff --git a/lib/behat/form_field/behat_form_select.php b/lib/behat/form_field/behat_form_select.php index ac63c01b337..19e0cf02dad 100644 --- a/lib/behat/form_field/behat_form_select.php +++ b/lib/behat/form_field/behat_form_select.php @@ -278,7 +278,7 @@ class behat_form_select extends behat_form_field { */ protected function get_selected_options($returntexts = true) { - $method = 'getText'; + $method = 'getHtml'; if ($returntexts === false) { $method = 'getValue'; } From 11f69d4165aecdae5fd7798f2c928cd4da90e0af Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Wed, 25 Jun 2014 11:29:40 +0800 Subject: [PATCH 2/4] MDL-43835 behat: Fixed backup behat test Disabling section, disables all checkboxes in section, So we don't have to unset them manually --- backup/util/ui/tests/behat/backup_courses.feature | 9 +++------ .../util/ui/tests/behat/restore_moodle2_courses.feature | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/backup/util/ui/tests/behat/backup_courses.feature b/backup/util/ui/tests/behat/backup_courses.feature index fdf1c13de6f..94e02e3c67e 100644 --- a/backup/util/ui/tests/behat/backup_courses.feature +++ b/backup/util/ui/tests/behat/backup_courses.feature @@ -29,8 +29,7 @@ Feature: Backup Moodle courses When I backup "Course 1" course using this options: | Initial | Include calendar events | 0 | | Initial | Include course logs | 1 | - | Schema | setting_section_section_5_userinfo | 0 | - | Schema | setting_section_section_5_included | 0 | + | Schema | Topic 5 | 0 | | Confirmation | Filename | test_backup.mbz | Then I should see "Restore" And I click on "Restore" "link" in the "test_backup.mbz" "table_row" @@ -50,10 +49,8 @@ Feature: Backup Moodle courses @javascript Scenario: Backup selecting just one section When I backup "Course 2" course using this options: - | Schema | setting_section_section_2_userinfo | 0 | - | Schema | setting_section_section_2_userinfo | 0 | - | Schema | setting_section_section_4_included | 0 | - | Schema | setting_section_section_4_included | 0 | + | Schema | Test data | 0 | + | Schema | Topic 2 | 0 | | Confirmation | Filename | test_backup.mbz | Then I should see "Course backup area" And I click on "Restore" "link" in the "test_backup.mbz" "table_row" diff --git a/backup/util/ui/tests/behat/restore_moodle2_courses.feature b/backup/util/ui/tests/behat/restore_moodle2_courses.feature index e5433f1e110..e5476caf5b4 100644 --- a/backup/util/ui/tests/behat/restore_moodle2_courses.feature +++ b/backup/util/ui/tests/behat/restore_moodle2_courses.feature @@ -52,10 +52,8 @@ Feature: Restore Moodle 2 course backups When I backup "Course 3" course using this options: | Confirmation | Filename | test_backup.mbz | And I restore "test_backup.mbz" backup into "Course 2" course using this options: - | Schema | setting_section_section_3_included | 0 | - | Schema | setting_section_section_3_userinfo | 0 | - | Schema | setting_section_section_5_included | 0 | - | Schema | setting_section_section_5_userinfo | 0 | + | Schema | Test database name | 0 | + | Schema | Section 2 | 0 | Then I should see "Course 2" And I should see "Test assign name" And I should not see "Test database name" @@ -70,8 +68,7 @@ Feature: Restore Moodle 2 course backups | Description | Test forum post backup description | And I follow "Restore" And I merge "test_backup.mbz" backup into the current course after deleting it's contents using this options: - | Schema | setting_section_section_8_userinfo | 0 | - | Schema | setting_section_section_8_included | 0 | + | Schema | Section 3 | 0 | Then I should see "Course 1" And I should not see "Section 3" And I should not see "Test forum post backup name" From 6c396b6bb4fa6f97f61c095ef86e4a34495ec5d1 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Wed, 25 Jun 2014 11:30:44 +0800 Subject: [PATCH 3/4] MDL-43835 behat: Added new step to set field with xpath defined --- badges/tests/behat/award_badge.feature | 3 +-- lib/tests/behat/behat_forms.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index ffe9b3d8bc0..0812ab70032 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -212,8 +212,7 @@ Feature: Award badges And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I set the field "type" to "Course completion" - And I set the following fields to these values: - | grade_2 | 0 | + And I set the field with xpath "//fieldset/input[1]" to "0" And I press "Save" And I press "Enable access" When I press "Continue" diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index b686efbdc6d..abdc35e253b 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -155,6 +155,25 @@ class behat_forms extends behat_base { $this->set_field_value($field, $value); } + /** + * Sets the specified value to the field with xpath. + * + * @Given /^I set the field with xpath "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)"$/ + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $field + * @param string $value + * @return void + */ + public function i_set_the_field_with_xpath_to($fieldxpath, $value) { + try { + $fieldNode = $this->find('xpath', $fieldxpath); + } catch (\Behat\Mink\Exception\ElementNotFoundException $e) { + throw new ElementNotFoundException('Field with xpath ' . $fieldxpath . 'not found, so can\'t be set'); + } + $field = behat_field_manager::get_form_field($fieldNode, $this->getSession()); + $field->set_value($value); + } + /** * Checks, the field matches the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. * From 004d7e35b0a2e425bea5c4db151791e95ba56827 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 24 Jun 2014 15:12:48 +0800 Subject: [PATCH 4/4] MDL-43835 behat: Use proper step for navigation expansion --- badges/tests/behat/add_badge.feature | 11 +++-------- badges/tests/behat/award_badge.feature | 6 +++--- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/badges/tests/behat/add_badge.feature b/badges/tests/behat/add_badge.feature index 37b534c79a0..ac038077a8b 100644 --- a/badges/tests/behat/add_badge.feature +++ b/badges/tests/behat/add_badge.feature @@ -10,9 +10,7 @@ Feature: Add badges to the system @javascript Scenario: Setting badges settings - Given I expand "Site administration" node - And I expand "Badges" node - And I follow "Badges settings" + Given I navigate to "Badges settings" node in "Site administration > Badges" And I set the field "Default badge issuer name" to "Test Badge Site" And I set the field "Default badge issuer contact details" to "testuser@test-badge-site.com" And I press "Save changes" @@ -22,15 +20,12 @@ Feature: Add badges to the system @javascript Scenario: Accessing the badges - Given I expand "Site pages" node - And I follow "Site badges" + Given I navigate to "Site badges" node in "Site pages" Then I should see "There are no badges available." @javascript Scenario: Add a badge - Given I expand "Site administration" node - And I expand "Badges" node - And I follow "Add a new badge" + Given I navigate to "Add a new badge" node in "Site administration > Badges" And I set the following fields to these values: | Name | Test Badge | | Description | Test badge description | diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index 0812ab70032..d277721b335 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -85,7 +85,7 @@ Feature: Award badges | student2 | C1 | student | And I log in as "teacher1" And I follow "Course 1" - And I click on "//span[text()='Badges']" "xpath_element" in the "Administration" "block" + And I navigate to "Add a new badge" node in "Course administration > Badges" And I follow "Add a new badge" And I set the following fields to these values: | Name | Course Badge | @@ -142,7 +142,7 @@ Feature: Award badges And I log out And I log in as "teacher1" And I follow "Course 1" - And I click on "//span[text()='Badges']" "xpath_element" in the "Administration" "block" + And I navigate to "Add a new badge" node in "Course administration > Badges" And I follow "Add a new badge" And I set the following fields to these values: | Name | Course Badge | @@ -203,7 +203,7 @@ Feature: Award badges And I log out And I log in as "teacher1" And I follow "Course 1" - And I click on "//span[text()='Badges']" "xpath_element" in the "Administration" "block" + And I navigate to "Add a new badge" node in "Course administration > Badges" And I follow "Add a new badge" And I set the following fields to these values: | Name | Course Badge |