Cypress is a test automation tool that make testing fairly easy. Here is what you need to start a project.
- NodeJS download
- Make sure that Add to PATH is included otherwise you need to do this manually later
- I also checked automatically install the necessary tools checkbox, but this is not required
- Installation will take quiet a bit longer
- pnpm installation
- Not mandatory but...
- When using npm, if you have 100 projects using a dependency, you will have 100 copies of that dependency saved on disk. With pnpm, the dependency will be stored in a content-addressable store
- Cypress: Open a terminal -
pnpm install cypress --save-dev
- Open a terminal
- Run
npx cypress open
- Windows Firewall Pop-up:
Allow Access
- Windows Firewall Pop-up:
- If everything went well you will see a Cypress Window asking
E2E Testing
/Component Testing
- Select
E2E Testing
- This will create a bunch of files that you need for E2E testing
- Read all about it if you want
- Click
Continue
- Select a browser (you will only see locally installed browsers) and hit
Start E2E Testing in ....
- Create your first spec has two options
Scaffold example specs
&Create new spec
- If you choose
Scaffold example specs
you do get a bunch of examples to play with - We choose
Create new spec
- Give it a name e.g.
my-first-spec
- Hit
Okay, run the spec
and see the magic
- Give it a name e.g.
- But to get familiar repeat this workshop in another empty project and select the other option to see what will happen
- If you choose
- Create your first spec has two options
- Select
- Add
"cypress:open": "cypress open"
toscripts
inpackage.json
- You can now run cypress with this npm command
npm run cypress:open
- Which you can also add to your run configurations if you want
- You can now run cypress with this npm command
- Writing your first end to end test
- Testing your app
- Add
baseUrl: 'https://example.cypress.io',
tocypress.config.js
- Replace
cy.visit('.....');
withcy.visit('\')
in your specfile and see what happens - Convert all .js files to .ts files
- Add
- Go over the best practices page