From 85fded1a95edee08202dc17506edc3c70a975466 Mon Sep 17 00:00:00 2001 From: abgreeve Date: Wed, 10 Nov 2021 13:16:51 +0800 Subject: [PATCH] MDL-71912 mod_lesson: New step definitions for behat. --- .../tests/behat/behat_mod_lesson_behat.php | 77 +++++++++++++++++++ .../tests/behat/lesson_delete_answers.feature | 4 +- .../tests/behat/lesson_edit_cluster.feature | 4 +- .../tests/behat/lesson_edit_pages.feature | 4 +- .../tests/behat/lesson_essay_question.feature | 4 +- .../behat/lesson_exit_enter_clusters.feature | 4 +- .../tests/behat/lesson_navigation.feature | 3 +- .../lesson_number_of_student_attempts.feature | 4 +- ...son_numerical_question_with_locale.feature | 10 +-- .../tests/behat/lesson_progress_bar.feature | 4 +- .../tests/behat/lesson_with_clusters.feature | 4 +- .../behat/lesson_with_subcluster.feature | 4 +- .../tests/behat/teacher_grade_essays.feature | 6 +- 13 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 mod/lesson/tests/behat/behat_mod_lesson_behat.php diff --git a/mod/lesson/tests/behat/behat_mod_lesson_behat.php b/mod/lesson/tests/behat/behat_mod_lesson_behat.php new file mode 100644 index 00000000000..9dd3ff3f270 --- /dev/null +++ b/mod/lesson/tests/behat/behat_mod_lesson_behat.php @@ -0,0 +1,77 @@ +. + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. +// For that reason, we can't even rely on $CFG->admin being available here. + +require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); + +use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; +use Behat\Mink\Exception\ExpectationException as ExpectationException; + +/** + * Step definitions related mod_lesson. + * + * @package mod_lesson + * @category test + * @copyright 2021 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_mod_lesson_behat extends behat_base { + + /** + * Select the lesson edit type [Collapsed|Expanded] + * + * @Given i select edit type :edittype + * + * @param string $edittype The edit type of either Collapsed or Expanded + */ + public function i_select_edit_type(string $edittype): void { + + $typestring = ($edittype == 'Collapsed') ? get_string('collapsed', 'mod_lesson') : get_string('full', 'mod_lesson'); + try { + $this->execute("behat_forms::i_select_from_the_singleselect", [$typestring, 'jump']); + } catch (ElementNotFoundException $e) { + $this->execute("behat_general::click_link", [$typestring]); + } + } + + /** + * Go to the lesson essay grading page. + * + * @Given i grade lesson essays + */ + public function i_grade_lesson_essays(): void { + try { + $this->execute("behat_general::i_click_on", [get_string('manualgrading', 'mod_lesson'), 'button']); + } catch (ElementNotFoundException $e) { + $this->execute("behat_general::click_link", [get_string('manualgrading', 'mod_lesson')]); + } + } + + /** + * Go to the lesson edit page. + * + * @Given i edit the lesson + */ + public function i_edit_the_lesson(): void { + try { + $this->execute("behat_general::click_link", [get_string('edit', 'mod_lesson')]); + } catch (ElementNotFoundException $e) { + $this->execute("behat_general::i_click_on", [get_string('edit', 'mod_lesson'), 'button']); + } + } +} diff --git a/mod/lesson/tests/behat/lesson_delete_answers.feature b/mod/lesson/tests/behat/lesson_delete_answers.feature index 4098b03e6db..2bf44c979b2 100644 --- a/mod/lesson/tests/behat/lesson_delete_answers.feature +++ b/mod/lesson/tests/behat/lesson_delete_answers.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, teacher can delete question answers and branch table contents In order to modify an existing lesson @@ -47,7 +47,7 @@ branch table contents | id_jumpto_1 | First page name | | id_score_1 | 0 | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" Scenario: Edit lesson content page Given I click on "//th[normalize-space(.)='First page name']/descendant::a[3]" "xpath_element" diff --git a/mod/lesson/tests/behat/lesson_edit_cluster.feature b/mod/lesson/tests/behat/lesson_edit_cluster.feature index b61d7e6177b..14f8598488a 100644 --- a/mod/lesson/tests/behat/lesson_edit_cluster.feature +++ b/mod/lesson/tests/behat/lesson_edit_cluster.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, teacher can edit a cluster page In order to modify an existing lesson and change navigation As a teacher @@ -29,7 +29,7 @@ Feature: In a lesson activity, teacher can edit a cluster page | id_answer_editor_0 | Next page | | id_jumpto_0 | Next page | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" And I set the field "Select a question type" to "Multichoice" diff --git a/mod/lesson/tests/behat/lesson_edit_pages.feature b/mod/lesson/tests/behat/lesson_edit_pages.feature index 9b23687bc4e..c0b2582ddcf 100644 --- a/mod/lesson/tests/behat/lesson_edit_pages.feature +++ b/mod/lesson/tests/behat/lesson_edit_pages.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, teacher can edit lesson's pages In order to modify an existing lesson As a teacher @@ -38,7 +38,7 @@ Feature: In a lesson activity, teacher can edit lesson's pages | id_answer_editor_1 | Next page | | id_jumpto_1 | Next page | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" And I set the field "Select a question type" to "Numerical" And I press "Add a question page" diff --git a/mod/lesson/tests/behat/lesson_essay_question.feature b/mod/lesson/tests/behat/lesson_essay_question.feature index 2c0ed6bbcb7..ae745bde134 100644 --- a/mod/lesson/tests/behat/lesson_essay_question.feature +++ b/mod/lesson/tests/behat/lesson_essay_question.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @_file_upload @skip_interim +@mod @mod_lesson @_file_upload Feature: In a lesson activity, teacher can add an essay question As a teacher I need to add an essay question in a lesson and grade student attempts @@ -47,7 +47,7 @@ Feature: In a lesson activity, teacher can add an essay question And I log in as "teacher1" And I am on "Course 1" course homepage And I follow "Test lesson name" - And I click on "Grade essays" "button" + And I grade lesson essays And I should see "Student 1" And I should see "Essay question" And I follow "Essay question" diff --git a/mod/lesson/tests/behat/lesson_exit_enter_clusters.feature b/mod/lesson/tests/behat/lesson_exit_enter_clusters.feature index 202f2aa4e91..98179496ea3 100644 --- a/mod/lesson/tests/behat/lesson_exit_enter_clusters.feature +++ b/mod/lesson/tests/behat/lesson_exit_enter_clusters.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, students can exit and re-enter the activity when it consists only of cluster pages As a student I need to exit and re-enter a lesson out and into clusters. @@ -28,7 +28,7 @@ Feature: In a lesson activity, students can exit and re-enter the activity when | id_answer_editor_0 | Next page | | id_jumpto_0 | Next page | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" And I follow "Update page: Cluster" And I set the following fields to these values: diff --git a/mod/lesson/tests/behat/lesson_navigation.feature b/mod/lesson/tests/behat/lesson_navigation.feature index 792c3e1585e..1e6fab136c6 100644 --- a/mod/lesson/tests/behat/lesson_navigation.feature +++ b/mod/lesson/tests/behat/lesson_navigation.feature @@ -18,7 +18,6 @@ Feature: In a lesson activity, students can navigate through a series of pages i | student1 | C1 | student | And I log in as "teacher1" - @skip_interim Scenario: Student navigation with pages and questions Given the following "activities" exist: | activity | name | intro | course | idnumber | @@ -41,7 +40,7 @@ Feature: In a lesson activity, students can navigate through a series of pages i | id_answer_editor_1 | Next page | | id_jumpto_1 | Next page | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" And I set the field "Select a question type" to "Numerical" And I press "Add a question page" diff --git a/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature b/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature index ed7ee6ca8c3..f39a0dd8edc 100644 --- a/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature +++ b/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In Dashboard, teacher can see the number of student attempts to lessons In order to know the number of student attempts to a lesson As a teacher @@ -68,7 +68,7 @@ Feature: In Dashboard, teacher can see the number of student attempts to lessons | id_response_editor_1 | Wrong | | id_jumpto_1 | This page | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" And I set the field "Select a question type" to "True/false" And I press "Add a question page" diff --git a/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature b/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature index 16be11e6248..384ff8ff2bb 100644 --- a/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature +++ b/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, I need to edit pages in the lesson taking into account locale settings Background: @@ -43,7 +43,7 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac Given I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I follow "Test lesson name" - And I click on "Edit" "button" in the "region-main" "region" + And I edit the lesson And I follow "Hardest question ever" Then I should see "2#87" And I should see "2#1:2#8" @@ -53,8 +53,8 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac Given I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I follow "Test lesson name" - And I click on "Edit" "button" in the "region-main" "region" - And I select "Expanded" from the "jump" singleselect + And I edit the lesson + And I select edit type "Expanded" Then I should see "2#87" And I should see "2#1:2#8" And I log out @@ -115,7 +115,7 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac | core_langconfig | decsep | , | And I am on "Course 1" course homepage with editing mode on And I follow "Test lesson name" - Then I click on "Edit" "button" in the "region-main" "region" + Then I edit the lesson And I follow "Hardest question ever" Then I should see "2,87" And I should see "2,1:2,8" diff --git a/mod/lesson/tests/behat/lesson_progress_bar.feature b/mod/lesson/tests/behat/lesson_progress_bar.feature index 5c08e2c7650..7c14d2a69fd 100644 --- a/mod/lesson/tests/behat/lesson_progress_bar.feature +++ b/mod/lesson/tests/behat/lesson_progress_bar.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, students can see their progress viewing a progress bar. In order to create a lesson with conditional paths As a teacher @@ -43,7 +43,7 @@ Feature: In a lesson activity, students can see their progress viewing a progres | id_answer_editor_1 | Next page | | id_jumpto_1 | Next page | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" And I set the field "Select a question type" to "Numerical" And I press "Add a question page" diff --git a/mod/lesson/tests/behat/lesson_with_clusters.feature b/mod/lesson/tests/behat/lesson_with_clusters.feature index 84305e619c4..fe75ae5fbc8 100644 --- a/mod/lesson/tests/behat/lesson_with_clusters.feature +++ b/mod/lesson/tests/behat/lesson_with_clusters.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, students can see questions in random order In order to create a lesson with clusters As a teacher @@ -40,7 +40,7 @@ Feature: In a lesson activity, students can see questions in random order | id_answer_editor_1 | Next page | | id_jumpto_1 | Next page | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][4]" "xpath_element" And I set the field "Select a question type" to "Multichoice" diff --git a/mod/lesson/tests/behat/lesson_with_subcluster.feature b/mod/lesson/tests/behat/lesson_with_subcluster.feature index 59fdabc2c02..3c6e3a942b4 100644 --- a/mod/lesson/tests/behat/lesson_with_subcluster.feature +++ b/mod/lesson/tests/behat/lesson_with_subcluster.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, students can see questions in random order and a single question drawn from a branch In order to create a lesson with a cluster and a subcluster As a teacher @@ -31,7 +31,7 @@ Feature: In a lesson activity, students can see questions in random order and a | id_answer_editor_0 | Next page | | id_jumpto_0 | Next page | And I press "Save page" - And I select "Expanded" from the "jump" singleselect + And I select edit type "Expanded" And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" And I set the field "Select a question type" to "Multichoice" diff --git a/mod/lesson/tests/behat/teacher_grade_essays.feature b/mod/lesson/tests/behat/teacher_grade_essays.feature index 04019116e47..3f518d322b5 100644 --- a/mod/lesson/tests/behat/teacher_grade_essays.feature +++ b/mod/lesson/tests/behat/teacher_grade_essays.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson @skip_interim +@mod @mod_lesson Feature: In a lesson activity, a non editing teacher can grade essay questions As a non editing teacher I need to grade student answers to essay questions in lesson @@ -69,7 +69,7 @@ Feature: In a lesson activity, a non editing teacher can grade essay questions And I am on "Course 1" course homepage And I follow "Test lesson name" Then I should see "Grade essays" - And I click on "Grade essays" "button" + And I grade lesson essays And I should see "Student 1" And I should see "Student 2" And I should see "Essay question" @@ -94,6 +94,6 @@ Feature: In a lesson activity, a non editing teacher can grade essay questions And I am on "Course 1" course homepage And I follow "Test lesson name" Then I should see "Grade essays" - And I click on "Grade essays" "button" + And I grade lesson essays And I should not see "Student 1" And I should see "Student 2"