Cypress is an open source testing tool.
- The
scripts
section defines 2 jobs:yarn test
- runs two parallel processes:
yarn start
, which is a wrapper to./dev local
, and runs the local applicationyarn cypress
, which opens cypress using chrome against the local instance
- runs two parallel processes:
yarn test:ci
- to be run in pipelines/actions
- runs cypress headless against the branch-specific instance of the application (eg. )
cypress.config.js
may use any of these config options.
There are two primary syntaxes for writing tests for Cypress.
- JavaScript
- uses extension
*.spec.js
located intests
directory
- uses extension
- Gherkin (Cucumber)
- uses extension
*.feature
located intests
directory - requires suitable JavaScript step definitions be created
- General use steps go in
support/step_definitions
directory - Feature specific steps go in same directory as your feature, with filename of
<feature>.stepdef.js
- eg
tests\e2e\admin\admin.feature
andtests\e2e\admin\admin.stepdef.js
- eg
- General use steps go in
- VS Code plugins available, Cucumber (Gherkin) Full Support recommended
- uses extension
Relevant Documentation
- Cypress Documentation
- Cucumber Preprocessor Documentation
- Gherkin Documentation
- Step Definitions Documentation
To run cypress tests locally you will go to the root of the project and you'll need to pass in environment variables for the state user and admin user passwords. The final command will look something like this:
CYPRESS_ADMIN_USER_PASSWORD=passwordhere CYPRESS_STATE_USER_PASSWORD=passwordhere yarn test
If you don't have these passwords you can find them in AWS SSM parameters in the mdct-mcr-dev account. Look for the parameter with a name like /configuration/default/cognito/bootstrapUsers/password
. Ask a repository contributor for help if needed.
If you run into errors after trying to run the cypress test command:
-try running yarn
at the root of the project
-run nvm use
along with the current version that the project is on
-cd into tests/cypress and run yarn
.
These variables are included in GitHub secrets for CI stages.
The cypress cli comes with a number of options/flags/behaviors built into it, which allow it to target browsers, configure parallelization, and so on.
When writing Cypress tests for an existing branch, create a new branch and write the tests there. For example, if the branch that needs tests is called branch1
, create a new branch called branch1-test
.
When the tests have been written, create a new PR for branch1-test
and set its base to branch1
. Submit this PR for review.