Overview
FastAPI 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/fastapi-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/fastapi-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": {
"admin": {
"username": "admin@example.com"
},
"user": {
"username": "user@example.com"
}
}
}
}
Steps
- Given I am signed in to the API as "admin"
- Given I am signed in to the app as "admin"
- Then the API should have refused "password" with "at least 8 characters"
- Then the API should have said "Incorrect email or password"
- Then the API's answer should match its documented schema
- Then the API should document "POST /api/v1/users/signup"
- When I open the API docs
- Then the API docs should list "POST /api/v1/login/access-token"
- When I authorize the API docs as "admin"
- When I try out "GET /api/v1/users/me" in the API docs
- When I try out "POST /api/v1/users/signup" in the API docs with:
- Then the API docs should show the answer 200
- When I wait for the app's API calls to finish
- Then the app should have called "POST /api/v1/items/"
- Then the app's call should have been accepted
- Then the app's call should have been refused with "The user with this email already exists"
- Then the app should show the message "Item created successfully"
- When I wait for the app's messages to go
- Then the app should have sent me to "/login" with a whole page load
- Then the app should show its not-found page
- Then the "Title" field should say "Title is required"
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/fastapi-steps.
Logo
The FastAPI icon is from github.com/fastapi/full-stack-fastapi-template (MIT), unmodified. FastAPI is a registered trademark of its owner; this pack is not affiliated with or endorsed by the FastAPI project.