Overview
Next.js 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/nextjs-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/nextjs-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",
"name": "Administrator"
},
"editor": {
"email": "editor@example.com",
"password": "dD.123123ddd",
"name": "Editor"
}
}
}
}
Steps
- Given I am a logged in user with the "administrator" user
- When I log in as "administrator" with the login form
- When I log in with the email "administrator@example.com" and the password "wrong-password"
- When I fill in the login form as "administrator"
- When I log out
- Then I should be logged in
- Then I should be logged in as "administrator"
- Then I should see the login form
- Then the login form should send me back to "/dashboard"
- When I wait for the page to be ready
- Then I should see a hydrated page
- Then there should be no hydration errors
- Then the site should be served as a production build
- Then the page should be served by the app router
- Then the page should run on the release "16"
- Then the page should be prerendered
- When I click the link "Invoices" without a full page reload
- When I go back without a full page reload
- Then the page should have a route announcer
- Then the route announcer should announce "Invoices | Acme Dashboard"
- Then the page "/dashboard/invoices" should be prefetched
- Given the network is slow
- When I start to go to "/dashboard/invoices"
- Then a part of the page should show its loading state
- Given the server's answers are held back
- When the server's answers come through
- Then the page should be waiting for the server
- When I wait for the page to finish loading
- When I send the form with "Create Invoice"
- Then the form should have been sent without a full page reload
- Then the field "Choose customer" should show the error "Please select a customer."
- Then the form should show the message "Missing Fields. Failed to Create Invoice."
- Then the "Log in" button should be busy
- Then I should be on a 404 page
- Then I should be on the default 404 page
- Then the error page should show "Something went wrong!"
- Then the page should not show the details of the error
- Then the development error overlay should be shown
- Then the development error overlay should show "invalid input syntax for type uuid"
- Then the development error overlay should list 2 errors
- Then the development tools should be on the page
- Then the image "Ivy Example's profile picture" should load lazily
- Then the image "logo" should be preloaded
- Then the image "Ivy Example's profile picture" should be optimized
- Then the image "Ivy Example's profile picture" should be served as "image/webp"
- Then the image "Ivy Example's profile picture" should have a width and a height
- Then the image "Ivy Example's profile picture" should have loaded
- When I scroll the image "Oak Example's profile picture" into view
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/nextjs-steps.