Overview
Moodle Steps adds step definitions to Webship-js 2.0.x for the markup the platform itself renders, regardless of theme or distribution, so scenarios read as plain sentences instead of CSS selectors. It is a plugin for Webship-js: it ships one file of step definitions you drop into an existing test project, and it composes with the built-in steps rather than duplicating them.
Install
npm install --save-dev @webship-js/moodle-steps
Then add its step file to cucumber.js beside the Webship-js steps:
require: [
'node_modules/webship-js/tests/step-definitions/**/*.js',
'node_modules/@webship-js/moodle-steps/tests/step-definitions/*.js',
'tests/step-definitions/**/*.js',
]
Test users
The steps that log in use accounts that already exist on the site, by the handle a feature names (Given I am a logged in user with the "admin" user). The site build creates them; a feature never creates or deletes an account. They are listed in cucumber.js under worldParameters. These are the test accounts of the pack's own test site: put the accounts of your site in your project, and keep real passwords in environment variables.
{
"worldParameters": {
"users": {
"administrator": {
"username": "administrator",
"password": "dD.123123ddd",
"email": "administrator@example.com",
"name": "Administrator User"
},
"manager": {
"username": "manager",
"password": "dD.123123ddd",
"email": "manager@example.com",
"name": "Manager User"
},
"teacher": {
"username": "teacher",
"password": "dD.123123ddd",
"email": "teacher@example.com",
"name": "Teacher User"
},
"student": {
"username": "student",
"password": "dD.123123ddd",
"email": "student@example.com",
"name": "Student User"
},
"student2": {
"username": "student2",
"password": "dD.123123ddd",
"email": "student2@example.com",
"name": "Student2 User"
}
}
}
}
Steps
- Given I am a logged in user with the "student" user
- When I log in as "student" with the login form
- When I log in with the username "student" and the password "wrong-password"
- When I log in as a guest
- When I log out
- Then I should be logged in
- Then I should be logged in as "student"
- Then I should be logged in as a guest
- Then I should see the login form
- Then I should see the error message "Your login info may be incorrect. Please try again."
- Then I should see the message "1 enrolled users"
- Then I should not see any error message
- When I wait for the page to be ready
- When I go to my dashboard
- When I go to my courses
- Then my courses should list "Software Testing 101"
- Then the course progress of "Software Testing 101" should be "0%"
- Then I should see the block "Timeline"
- Then the timeline should list "Testing diary"
- Then I should have access to "/course/management.php"
- Then the access to "/course/management.php" should be:
- When I open the course "Software Testing 101"
- Then I should be on the course page
- Then I should see the enrolment options of the course
- Then the course sections should be:
- Then the section "Getting started" should list the activity "Testing diary"
- When I open the activity "Testing diary"
- Then the activity "Course handbook" should be marked as done
- Then the activity "Course handbook" should require "View"
- When I mark the activity "Class discussion" as done
- When I go to the "Participants" page of the course
- When I enrol "student2" in the course as "Student"
- When I unenrol "student2" from the course
- Then "student" should be enrolled in the course
- Then "student" should have the role "Student" in the course
- When I assign the role "Non-editing teacher" to "student" in the course
- When I remove the role "Non-editing teacher" from "student" in the course
- When I enrol myself in the course "Software Testing 101" with the key "TEST101-key"
- Then enrolling myself in the course "Software Testing 101" with the key "wrong-key" should be refused with "Incorrect enrolment key, please try again"
- When I unenrol myself from the course "Software Testing 101"
- When I submit the text "Found a defect in the login form." for the assignment "Testing diary"
- Then the "Submission status" of the assignment "Testing diary" should be "Submitted for grading"
- When I remove my submission for the assignment "Testing diary"
- When I grade "student" with "85" for the assignment "Testing diary"
- When I clear the grade of "student" for the assignment "Testing diary"
- Then the "Needs grading" count of the assignment "Testing diary" should be "1"
- Then my grade for the assignment "Testing diary" should be "85.00 / 100.00"
- When I start an attempt at the quiz "Basics quiz"
- When I answer "True" to the question "Testing can show that defects are present."
- When I submit the quiz attempt
- Then the "Grade" of the attempt should be "10.00 out of 10.00 (100%)"
- Then the question "Testing can show that defects are present." should be marked "Correct"
- Then my highest grade at the quiz "Basics quiz" should be "10.00 / 10.00"
- When I delete the attempts of "student" at the quiz "Basics quiz"
- When I post the discussion "A question about flaky tests" with the message "Why does a test pass here and fail in CI?" in the forum "Class discussion"
- When I reply "Wait on the page, not on the clock." to the discussion "A question about flaky tests" in the forum "Class discussion"
- Then the forum "Class discussion" should list the discussion "A question about flaky tests"
- Then the discussion "A question about flaky tests" in the forum "Class discussion" should have the reply "Wait on the page, not on the clock."
- When I delete the discussion "A question about flaky tests" from the forum "Class discussion"
- Then the grader report should show "85.00" for "student" in "Testing diary"
- Then my grade for "Testing diary" in the user report should be "85.00"
- When I send the message "Hello, when is the next quiz?" to "teacher"
- Then I should have the message "Hello, when is the next quiz?" from "student"
- When I delete my conversation with "teacher"
- Then I should have the notification "Welcome to Software Testing 101"
- When I mark all my notifications as read
- When I add the event "Study group" to my calendar
- Then my calendar should show the event "Study group"
- When I delete the event "Study group" from my calendar
- Then the upcoming events should list "Testing diary is due"
- When I search the site administration for "guest login button"
- Then the site administration search should find the setting "Guest login button"
- Then the setting "Guest login button" should be "Show"
- Then the category "Test courses" should list the course "Software Testing 101"
- When I create the course "Throwaway course" with the short name "THROW1" in the category "Test courses"
- When I delete the course "Throwaway course" from the category "Test courses"
Every assertion step reads both polarities from one definition: should see and should not see are the same step. Source and issues: github.com/webship/moodle-steps.