Overview
Discourse 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/discourse-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/discourse-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",
"email": "administrator@example.com",
"password": "dD.123123ddd"
},
"moderator": {
"username": "moderator",
"email": "moderator@example.com",
"password": "dD.123123ddd"
},
"member": {
"username": "member",
"email": "member@example.com",
"password": "dD.123123ddd"
},
"newuser": {
"username": "newuser",
"email": "newuser@example.com",
"password": "dD.123123ddd"
}
}
}
}
Steps
- Given I am a logged in user with the "member" user
- When I log in as "member" with the login form
- When I log in with the username "member" and the password "Wrong-password-1"
- Given I am not logged in
- Then the login should be refused with "Incorrect username, email or password"
- When I log out
- Then I should be logged in
- Then I should not be logged in
- Then I should be on the login page
- Given I am on the "Latest" topic list
- Then the topic list should be "All latest topics"
- Then the topic list should show "How to install the product on a laptop"
- Then the topic list should show the topics:
- Then the first topic of the list should be "How to install the product on a laptop"
- Then the topic list should be empty
- Then the topic "Where are the nightly backups kept" in the list should be in the category "Support"
- Then the topic "How to install the product on a laptop" in the list should have the tag "howto"
- Then the topic "Favourite keyboard shortcuts of the team" in the list should have 3 replies
- Then the topic "A topic the suite reads today" in the list should be new
- When I open "How to install the product on a laptop" from the list
- Then the categories page should list "Support"
- When I go to the category "Support"
- Then the tags page should list "howto"
- When I open the topic "How to install the product on a laptop"
- Then I should be reading the topic "How to install the product on a laptop"
- When I read the topic
- When I set the notifications of the topic to "Tracking"
- Then the notifications of the topic should be "Tracking"
- Then the topic should have 3 posts
- Then post 1 should be by "member"
- Then post 1 should read "Which keyboard shortcuts do you use every day?"
- When I reply to the topic with "A reply written by the suite for this scenario."
- When I quote post 2 in a reply
- Then the last post should quote "moderator"
- When I like post 2
- Then post 2 should have 1 like
- When I bookmark post 1
- Then post 1 should be bookmarked
- When I flag post 2 as "It's Off-Topic"
- Then post 2 should show "You flagged this as off-topic"
- When I open the composer for a new topic
- When I write the title "A topic the member writes today" in the composer
- When I write "A body written by the suite for this scenario." in the composer
- When I add "I agree with this answer." to the composer
- When I choose the category "Support" in the composer
- When I add the tag "howto" in the composer
- When I submit the composer
- When I try to submit the composer
- Then the composer should show the error "Title must be at least 15 characters"
- Then the composer should show "The body of a draft that the suite saves and resumes."
- Then the composer should have the title "A draft that is never posted"
- When I show the composer preview
- Then the composer preview should show "written by the suite"
- When I save the draft and close the composer
- When I resume the draft "A draft that is never posted"
- When I discard the composer
- Then the composer should be closed
- When I open the notifications menu
- Then the notifications menu should list "moderator A topic with a mention in it"
- When I open the notification "A topic with a mention in it"
- Then the avatar should show "1 new message notification"
- When I go to my messages
- Then my messages should list "A message the member reads today"
- When I open the composer for a new message
- When I add the recipient "moderator" in the composer
- When I send the message "A message the member sends today" to "moderator" with "A message written by the suite for this scenario."
- Then the message should be between "member" and "moderator"
- Then I should not be able to start a message
- When I search for "backups"
- Then the quick search should show "Where are the nightly backups kept"
- When I search the full page for "backups"
- When I filter the search by the category "Support"
- Then the search should find 1 result
- Then the search results should show "Where are the nightly backups kept"
- Then the search field should read "backups #support"
- When I open the profile of "member"
- Then the profile should show the name "Member Webship"
- Then the profile should show "Amman test office"
- When I go to my "Profile" preferences
- When I set the preference "Location" to "Amman test office"
- When I save my preferences
- Then the preference "Location" should be "Amman test office"
- When I close the topic
- When I pin the topic until "Next month"
- When I pin the topic globally until "Two weeks"
- When I unpin the topic
- When I try to pin the topic without a time
- Then the pin dialog should show the error "A date is required to pin this topic."
- When I unlist the topic
- Then the topic should be closed
- Then the topic should show the action "Closed"
- Then I should not see the topic admin menu
- When I go to the review queue
- Then the review queue should list the flagged post "A reply the member flags as off-topic."
- When I answer "Keep post" to the flagged post "A reply the member flags as off-topic."
- When I go to the admin dashboard
- Then the admin dashboard should show "Site traffic"
- When I search the site settings for "title"
- Then the site settings should list "title"
- Then the site setting "title" should be "Webship test forum"
- Then I should not be allowed to open "/admin"
- Given there is a topic "A topic the suite reads today" in "General" by "moderator"
- Given there is a topic "A topic with tags for the suite" in "Support" by "member" with:
- Given there is a message "A message the member reads today" from "moderator" to "member"
- Given "moderator" replied to the topic "A topic the suite reads today" with "A reply of the moderator for the suite."
- Given there is no topic "A topic the member writes today"
- Then there should be a topic "A topic the member writes today"
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/discourse-steps.