Overview
Strapi 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/strapi-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/strapi-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": {
"email": "administrator@example.com",
"password": "dD.123123ddd"
},
"editor": {
"email": "editor@example.com",
"password": "dD.123123ddd"
},
"author": {
"email": "author@example.com",
"password": "dD.123123ddd"
}
}
}
}
Steps
- Given I am a logged in user with the "editor" user
- When I log in as "editor" with the login form
- When I log in with the email "nobody@example.com" and the password "Wrong-password-1"
- Given I am not logged in
- Then the login should be refused with "Invalid credentials"
- When I log out
- Then I should be logged in
- Then I should not be logged in
- Then I should be on the admin login page
- Given I am on the "Article" list
- Then the list should count 24 entries
- Then the list should show "Harbour lights at dusk"
- Then the list should show the entries:
- Then the list should have 10 rows
- Then the "Harbour lights at dusk" row should show "harbour-lights-at-dusk" in the "slug" column
- Then the status of "Harbour lights at dusk" in the list should be "Published"
- When I search the list for "river"
- When I clear the search of the list
- When I sort the list by "title"
- Then the first row of the list should be "A city that walks"
- When I filter the list where "Status" "is" "Draft (never published)"
- Then the list should have the filter "Status is draft"
- When I remove the filter "Status is draft"
- When I show the "category" column
- When I reset the columns of the list
- Then the list should have the column "category"
- When I go to page 2 of the list
- Then the list should be on page 2
- Then the list should have 3 pages
- When I show 20 entries per page
- When I switch the list to "French (fr)"
- When I select "Bulk test article one" in the list
- When I select all entries on the page
- Then the selection should read "2 entries selected"
- Then the selection should offer "Publish"
- When I publish the selected entries
- When I unpublish the selected entries
- When I open "Harbour lights at dusk" from the list
- When I create a new entry from the list
- Then the list should be empty
- When I open the "Homepage" single type
- When I create a new "Article" entry
- When I set "title" to "Editor test article"
- When I set these fields:
- Then "title" should be set to "Editor test article"
- When I regenerate the "slug"
- When I choose "Guides" in the "category" relation
- When I remove "Guides" from the "category" relation
- Then the "category" relation should list "Guides"
- When I choose the asset "meadow.png" for "cover"
- When I remove the asset "meadow.png" from "cover"
- Then "cover" should hold the asset "meadow.png"
- When I save the entry
- When I publish the entry
- When I unpublish the entry
- When I discard the changes of the entry
- When I delete the entry
- Then the status of the entry should be "Draft"
- Then I should see the notification "Saved document"
- Then the "title" field should show the error "This value is required."
- Then I should not be able to publish the entry
- When I view the published version of the entry
- Then the form should be read only
- When I switch the entry to "French (fr)"
- Then the entry should be in "French (fr)"
- When I fill the entry in from "English (en)"
- When I leave the entry without saving
- When I add the "Quote" component to "blocks"
- When I set "body" to "A quotation for the test." in the "Quote" component of "blocks"
- Then "body" should be set to "A quotation for the test." in the "Quote" component of "blocks"
- When I move the "Quote" component of "blocks" down
- When I remove the "Quote" component from "blocks"
- Then the "blocks" dynamic zone should hold "Quote", "Rich text" and "Media"
- Given I am on the media library
- When I open the folder "Covers" in the media library
- Then the folder should count 2 items
- Then the media library should show "meadow.png"
- When I upload "test-lighthouse.png" to the media library
- Then the upload should be refused with "File is not a valid image"
- When I create the folder "Test folder" in the media library
- When I delete "test-lighthouse.png" from the media library
- When I open the details of "meadow.png"
- Then the "Dimensions" of the file should be "640 × 400"
- When I set "Alternative text" to "A lighthouse ring on blue" in the file details
- Then "Alternative text" should be set to "A lighthouse ring on blue" in the file details
- When I save the file details
- When I close the file details
- When I go to the "Settings" section
- Then the main navigation should list "Content-Type Builder"
- When I go to the settings page "API Tokens"
- Then the settings menu should list "API Tokens"
- Then the plan of the site should be "Community"
- Then the settings list should show "Read Only"
- When I open "Editor" from the settings list
- Then the role should allow "Publish" on "Article"
- Then the API token should be "Read-only"
- Then the account "editor" should have the role "Editor"
- Then I should not be allowed to open "/admin/settings/roles"
- When I open the model of "Article"
- Then the model should have the fields:
- Then the "blocks" dynamic zone of the model should offer "Quote", "Rich text" and "Media"
- Then the model should not allow changes
- Given there is an "Article" entry "Data step article"
- Given there is a published "Article" entry "Published test article"
- Given there is an "Article" entry "Table test article" with:
- Given there is no "Article" entry "Editor test article"
- Then there should be an "Article" entry "Editor test article"
- Then there should be a file "test-lighthouse.png" in the media library
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/strapi-steps.