Skip to content

Commit

Permalink
MDL-75230 behat: Lesson Behat tests optimised
Browse files Browse the repository at this point in the history
Replace steps that manually add Lesson instances via the UI and use
Behat generators. This improves the speed of the Behat test runs.
  • Loading branch information
andelacruz committed Feb 8, 2023
1 parent 0780e87 commit 367027f
Show file tree
Hide file tree
Showing 41 changed files with 248 additions and 659 deletions.
8 changes: 4 additions & 4 deletions admin/tool/behat/tests/behat/get_and_set_fields.feature
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ Feature: Verify that all form fields values can be get and set

@javascript
Scenario: with JS enabled all form fields getters and setters works as expected
Given the following "activities" exist:
| activity | course | name |
| lesson | C1 | Test lesson |
Then I am on the "Course 1" "groups" page
# Select (multi-select & AJAX) - Checking "I set the field" and "select box should contain".
And I set the field "groups" to "Group 2"
Expand All @@ -150,11 +153,8 @@ Feature: Verify that all form fields values can be get and set
And the "members" select box should contain "Student 2 ([email protected])"
And the "members" select box should not contain "Student 3 ([email protected])"
# Checkbox (AJAX) - Checking "I set the field" and "I set the following fields to these values".
And I am on "Course 1" course homepage
And I add a "Lesson" to section "1"
And I am on the "Test lesson" "lesson activity editing" page
And I set the following fields to these values:
| Name | Test lesson |
| Description | Test lesson description |
| available[enabled] | 1 |
And I set the field "deadline[enabled]" to "1"
# Checkbox (AJAX) - Checking "the field matches value" before saving.
Expand Down
22 changes: 8 additions & 14 deletions grade/tests/behat/grade_to_pass.feature
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ Feature: We can set the grade to pass value

Scenario: Set a valid grade to pass for lesson activity
Given the following "activities" exist:
| activity | name | intro | course | section | idnumber |
| lesson | Test Lesson 1 | Test | C1 | 1 | lesson1 |
| activity | name | course | idnumber |
| lesson | Test Lesson 1 | C1 | lesson1 |
And I am on "Course 1" course homepage with editing mode on
And I am on the "Test Lesson 1" "lesson activity" page
And I navigate to "Settings" in current page administration
And I am on the "Test Lesson 1" "lesson activity editing" page
And I set the following fields to these values:
| Grade to pass | 90 |
And I press "Save and return to course"
Expand All @@ -184,21 +183,18 @@ Feature: We can set the grade to pass value
Then the field "Grade to pass" matches value "90"
And I set the field "Grade to pass" to "80"
And I press "Save changes"
And I am on "Course 1" course homepage
And I am on the "Test Lesson 1" "lesson activity" page
And I follow "Settings"
And I am on the "Test Lesson 1" "lesson activity editing" page
And the field "Grade to pass" matches value "80"

Scenario: Set a valid grade to pass for lesson activity with custom decimal separator
Given the following "activities" exist:
| activity | name | intro | course | section | idnumber |
| lesson | Test Lesson 1 | Test | C1 | 1 | lesson1 |
| activity | name | course | idnumber |
| lesson | Test Lesson 1 | C1 | lesson1 |
And the following "language customisations" exist:
| component | stringid | value |
| core_langconfig | decsep | # |
And I am on "Course 1" course homepage with editing mode on
And I am on the "Test Lesson 1" "lesson activity" page
And I navigate to "Settings" in current page administration
And I am on the "Test Lesson 1" "lesson activity editing" page
And I set the following fields to these values:
| Grade to pass | 90#50 |
And I press "Save and return to course"
Expand All @@ -208,9 +204,7 @@ Feature: We can set the grade to pass value
Then the field "Grade to pass" matches value "90#50"
And I set the field "Grade to pass" to "80"
And I press "Save changes"
And I am on "Course 1" course homepage
And I am on the "Test Lesson 1" "lesson activity" page
And I follow "Settings"
And I am on the "Test Lesson 1" "lesson activity editing" page
And the field "Grade to pass" matches value "80#00"

Scenario: Set a valid grade to pass for database activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Feature: Using the lesson activities which support point scale
| course | C1 |
| activity | lesson |
| name | Test lesson name |
| intro | Test forum description |
| idnumber | lesson1 |

@javascript
Expand All @@ -37,11 +36,9 @@ Feature: Using the lesson activities which support point scale
| id_enableotheranswers | 1 |
| id_jumpto_6 | Next page |
And I press "Save page"
And I log out
And I am on the "Test lesson name" "lesson activity" page logged in as student1
And I set the field "Your answer" to "5"
And I press "Submit"
And I log out
And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1
And I expand all fieldsets
Then the "Maximum grade" "field" should be disabled
8 changes: 4 additions & 4 deletions media/player/videojs/tests/behat/modules.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Feature: Embed videos without the media filter

@javascript
Scenario: Add a video as content to a lesson. Make sure media filters work
When I add a "Lesson" to section "1"
And I set the following fields to these values:
| Name | Lesson with video |
| Description | Example of a video in a lesson |
Given the following "activities" exist:
| activity | course | section | name |
| lesson | Acceptance test site | 1 | Lesson with video |
When I am on the "Lesson with video" "lesson activity editing" page
And I expand all fieldsets
And I upload "media/player/videojs/tests/fixtures/test.mov" file to "Linked media" filemanager
And I press "Save and display"
Expand Down
20 changes: 4 additions & 16 deletions mod/lesson/tests/behat/all_other_answers_catch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ Feature: Numeric and short answer questions have a section to catch all other st
| course | C1 |
| idnumber | 0001 |
| name | Test lesson name |
| intro | Test lesson description |
| section | 1 |
| maxattempts | 3 |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test lesson name"
When I navigate to "Settings" in current page administration
And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1
And I expand all fieldsets
And I set the following fields to these values:
| Provide option to try a question again | Yes |
And I press "Save and return to course"
And I follow "Test lesson name"
And I press "Save and display"

Scenario: I can create a numerical question with an option to catch all student responses.
Given I follow "Add a question page"
Expand All @@ -53,10 +47,7 @@ Feature: Numeric and short answer questions have a section to catch all other st
| id_answer_editor_0 | End this lesson |
| id_jumpto_0 | End of lesson |
And I press "Save page"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test lesson name"
And I am on the "Test lesson name" "lesson activity" page logged in as student1
And I set the field "Your answer" to "5"
And I press "Submit"
And I should see "That's the wrong answer"
Expand Down Expand Up @@ -87,10 +78,7 @@ Feature: Numeric and short answer questions have a section to catch all other st
| id_answer_editor_0 | End this lesson |
| id_jumpto_0 | End of lesson |
And I press "Save page"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test lesson name"
And I am on the "Test lesson name" "lesson activity" page logged in as student1
And I set the field "Your answer" to "dog"
And I press "Submit"
And I should see "That's the wrong answer"
Expand Down
19 changes: 5 additions & 14 deletions mod/lesson/tests/behat/completion_condition_end_reached.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@ Feature: Set end of lesson reached as a completion condition for a lesson
| course | C1 |
| idnumber | 0001 |
| name | Test lesson |
| intro | Test lesson description |
| section | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Enable completion tracking | Yes |
And I press "Save and display"
And I follow "Test lesson"
And I navigate to "Settings" in current page administration
And I am on the "Test lesson" "lesson activity editing" page
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| completionview | 0 |
| completionendreached | 1 |
And I press "Save and return to course"
And I follow "Test lesson"
And I press "Save and display"
And I follow "Add a content page"
And I set the following fields to these values:
| Page title | First page name |
Expand All @@ -53,24 +49,19 @@ Feature: Set end of lesson reached as a completion condition for a lesson
| id_answer_editor_1 | Next page |
| id_jumpto_1 | Next page |
And I press "Save page"
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
When I am on the "Course 1" course page logged in as student1
Then the "Go through the activity to the end" completion condition of "Test lesson" is displayed as "todo"
And I follow "Test lesson"
And I press "Next page"
And I am on "Course 1" course homepage
And the "Go through the activity to the end" completion condition of "Test lesson" is displayed as "todo"
And I am on "Course 1" course homepage
And I follow "Test lesson"
And I am on the "Test lesson" "lesson activity" page
And I should see "You have seen more than one page of this lesson already."
And I should see "Do you want to start at the last page you saw?"
And I click on "No" "link" in the "#page-content" "css_element"
And I press "Next page"
And I press "Next page"
And I am on "Course 1" course homepage
And the "Go through the activity to the end" completion condition of "Test lesson" is displayed as "done"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I am on the "Course 1" course page logged in as teacher1
And "Student 1" user has completed "Test lesson" activity
34 changes: 12 additions & 22 deletions mod/lesson/tests/behat/completion_condition_time_spent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,19 @@ Feature: Set time spent as a completion condition for a lesson
| course | C1 |
| idnumber | 0001 |
| name | Test lesson |
| intro | Test lesson description |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I am on the "Course 1" course page logged in as teacher1
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Enable completion tracking | Yes |
And I press "Save and display"
And I follow "Test lesson"
And I navigate to "Settings" in current page administration
And I am on the "Test lesson" "lesson activity editing" page
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| completionview | 0 |
| completiontimespentenabled | 1 |
| completiontimespent[timeunit] | 1 |
| completiontimespent[number] | 10 |
And I press "Save and return to course"
And I am on "Course 1" course homepage
And I follow "Test lesson"
| completiontimespent[number] | 5 |
And I press "Save and display"
And I follow "Add a content page"
And I set the following fields to these values:
| Page title | First page name |
Expand All @@ -55,28 +50,23 @@ Feature: Set time spent as a completion condition for a lesson
| id_answer_editor_1 | Next page |
| id_jumpto_1 | Next page |
And I press "Save page"
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
Then the "Spend at least 10 secs on this activity" completion condition of "Test lesson" is displayed as "todo"
When I am on the "Course 1" course page logged in as student1
Then the "Spend at least 5 secs on this activity" completion condition of "Test lesson" is displayed as "todo"
And I follow "Test lesson"
And I press "Next page"
# Add 1 sec delay so lesson knows a valid attempt has been made in past.
And I wait "1" seconds
And I press "Next page"
And I should see "You completed this lesson in"
And I should see ", which is less than the required time of 10 secs. You might need to attempt the lesson again."
And I am on "Course 1" course homepage
And the "Spend at least 10 secs on this activity" completion condition of "Test lesson" is displayed as "todo"
And I should see ", which is less than the required time of 5 secs. You might need to attempt the lesson again."
And I am on "Course 1" course homepage
And I follow "Test lesson"
And the "Spend at least 5 secs on this activity" completion condition of "Test lesson" is displayed as "todo"
And I am on the "Test lesson" "lesson activity" page
And I press "Next page"
And I wait "11" seconds
And I wait "5" seconds
And I press "Next page"
And I should not see "You might need to attempt the lesson again."
And I am on "Course 1" course homepage
And the "Spend at least 10 secs on this activity" completion condition of "Test lesson" is displayed as "done"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And the "Spend at least 5 secs on this activity" completion condition of "Test lesson" is displayed as "done"
And I am on the "Course 1" course page logged in as teacher1
And "Student 1" user has completed "Test lesson" activity
33 changes: 9 additions & 24 deletions mod/lesson/tests/behat/date_availability.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,48 @@ Feature: A teacher can set available from and deadline dates to access a lesson
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | course | idnumber |
| lesson | Test lesson | C1 | lesson1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on

Scenario: Forbidding lesson accesses until a specified date
Given the following "activities" exist:
| activity | name | intro | course | section | idnumber |
| lesson | Test lesson | Test lesson description | C1 | 1 | lesson1 |
And I am on "Course 1" course homepage
And I follow "Test lesson"
And I navigate to "Settings" in current page administration
Given I am on the "Test lesson" "lesson activity editing" page
And I set the field "id_available_enabled" to "1"
And I set the following fields to these values:
| available[day] | 1 |
| available[month] | January |
| available[year] | 2030 |
| available[hour] | 08 |
| available[minute] | 00 |
And I press "Save and return to course"
And I follow "Test lesson"
And I press "Save and display"
And I follow "Add a content page"
And I set the following fields to these values:
| Page title | First page name |
| Page contents | First page contents |
| Description | The first one |
And I press "Save page"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
When I follow "Test lesson"
When I am on the "Test lesson" "lesson activity" page logged in as student1
Then the activity date in "Test lesson" should contain "Opens: Tuesday, 1 January 2030, 8:00"
And I should not see "First page contents"

Scenario: Forbidding lesson accesses after a specified date
Given the following "activities" exist:
| activity | name | intro | course | section | idnumber |
| lesson | Test lesson | Test lesson description | C1 | 1 | lesson1 |
And I am on "Course 1" course homepage
And I follow "Test lesson"
And I navigate to "Settings" in current page administration
Given I am on the "Test lesson" "lesson activity editing" page
And I set the field "id_deadline_enabled" to "1"
And I set the following fields to these values:
| deadline[day] | 1 |
| deadline[month] | January |
| deadline[year] | 2000 |
| deadline[hour] | 08 |
| deadline[minute] | 00 |
And I press "Save and return to course"
And I follow "Test lesson"
And I press "Save and display"
And I follow "Add a content page"
And I set the following fields to these values:
| Page title | First page name |
| Page contents | First page contents |
| Description | The first one |
And I press "Save page"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
When I follow "Test lesson"
When I am on the "Test lesson" "lesson activity" page logged in as student1
Then the activity date in "Test lesson" should contain "Closed: Saturday, 1 January 2000, 8:00"
And I should not see "First page contents"
13 changes: 3 additions & 10 deletions mod/lesson/tests/behat/display_lesson_description.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,20 @@ Feature: Display the lesson description in the lesson and optionally in the cour
| idnumber | 0001 |
| name | Test lesson name |
| intro | Test lesson description |
| section | 1 |
And I am on the "Test lesson name" "lesson activity" page logged in as teacher1
And I follow "Add a content page"
And I set the following fields to these values:
| Page title | Test lesson part 1 |
| Description | Lesson part 1 description |
| Jump | Next page |
And I click on "Save page" "button"
And I log in as "teacher1"

Scenario: Description is displayed in the Lesson
Given I am on "Course 1" course homepage
When I follow "Test lesson"
When I am on the "Test lesson name" "lesson activity" page
Then I should see "Test lesson description"

Scenario: Show lesson description in the course homepage
Given I am on "Course 1" course homepage
And I follow "Test lesson"
And I navigate to "Settings" in current page administration
Given I am on the "Test lesson name" "lesson activity editing" page
And the following fields match these values:
| Display description on course page | |
And I set the following fields to these values:
Expand All @@ -48,9 +43,7 @@ Feature: Display the lesson description in the lesson and optionally in the cour
Then I should see "Test lesson description"

Scenario: Hide lesson description in the course homepage
Given I am on "Course 1" course homepage
And I follow "Test lesson"
And I navigate to "Settings" in current page administration
Given I am on the "Test lesson name" "lesson activity editing" page
And the following fields match these values:
| Display description on course page | |
And I press "Save and return to course"
Expand Down
Loading

0 comments on commit 367027f

Please sign in to comment.