Overview
ASP.NET Core 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/aspnet-core-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/aspnet-core-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"
},
"user": {
"email": "user@example.com",
"password": "dD.123123ddd"
},
"twofactoruser": {
"email": "twofactoruser@example.com",
"password": "dD.123123ddd",
"otpSecret": "JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP"
},
"lockeduser": {
"email": "lockeduser@example.com",
"password": "dD.123123ddd"
},
"unconfirmeduser": {
"email": "unconfirmeduser@example.com",
"password": "dD.123123ddd"
}
}
}
}
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 "user@example.com" and the password "Wrong-password-1"
- Given I am not logged in
- Given I am on the login page
- When I go to the login page
- When I submit the login form as "twofactoruser"
- Then the login should be refused with "Invalid login attempt."
- Then I should be on the login page
- Then I should see the login form
- When I log out
- When I go to the logout page
- Then I should be asked to confirm the logout
- When I confirm the logout
- Then I should be logged in
- Then I should be logged in as "administrator"
- When my session expires
- Then the session cookie should be HttpOnly
- Then the session cookie should be SameSite Lax
- Then the session cookie should last 14 days
- Then this browser should be remembered for two-factor sign-in
- When I close the browser and open it again
- Then I should be back on the page I asked for
- Then I should be asked for the authenticator code
- When I enter the authenticator code of "twofactoruser"
- When I enter the authenticator code "000000"
- Then the authenticator code should be refused with "Invalid authenticator code."
- When I set up two-factor authentication with an authenticator app
- When I verify the authenticator app with the code "123456"
- When I turn two-factor authentication off
- Then two-factor authentication should be on
- Then I should see 10 recovery codes
- Then an email with the subject "Reset your password" should be sent to "user"
- Then no email should be sent to "nobody@example.com"
- Then the email with the subject "Reset your password" to "user" should contain "If you didn't request a password reset, you can ignore this email."
- When I open the "clicking here" link of the email to "user"
- When I ask for a password reset link for "user"
- When I reset the password of "user" on the reset page
- When I ask for a new confirmation email for "unconfirmeduser"
- When I try to register with:
- Then I should see the lockout page
- Then I should see the access denied page
- When I go to the "Password" page of my account
- Then I should be on the "Password" page of my account
- Then I should see the status message "Your profile has been updated"
- When I change my password to "Changed-Pass-123"
- When I change my password back
- When I change my email to "user-changed@example.com"
- When I change my email back
- When I download my personal data
- Then my personal data should show "Email" as "user@example.com"
- Then I should not be allowed to open "/Admin"
- Then every form that posts on this page should carry an anti-forgery token
- Then the form of the "Log in" button should carry an anti-forgery token
- When I press "Save" with a forged token
- When a page of another site sends a form to "/Identity/Account/Logout"
- When a page of another site sends a form to "/Movies/Edit/2" with:
- Then the form of the other site should be refused
- Then I should see the 404 error page
- Then the page should not show debug information
- Then I should see the developer exception page
- Then the error page should show its request ID
- Then the "Email" field should have the error "The Email field is required."
- Then the "Email" field should have no error
- Then the form should show the errors:
- Then the form should show the error "Username 'user@example.com' is already taken."
- Then the form should show no errors
- When I press "Create" with the checks of the page turned off
- Then the details should show "Genre" as "Comedy"
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/aspnet-core-steps.