✅ How to test a web application with functional browser tests (aka E2E tests)
Check if you have an app running on http://localhost:3000/
. If so, you are ready.
If not, then
- Open a terminal at the same place as the
package.json
npm start
to start the web app- Open application at http://localhost:3000/
"Fast, easy and reliable testing for anything that runs in a browser."(Cypress.io)
In new terminal, without stopping the web app
npx cypress open
💡 Tests live in cypress/integration
folder
- In your IDE open
cypress/integration/e2e/exercise.spec.js
- Follow instructions to implement
it('loads')
test
Here's an e2e test to validate that a link works
it('should click link', () => {
cy.visit('/');
cy.get('.App-link').click().url().should('contain', 'ultimateqa.com');
});
Click here to see answer.
- We should never need to test that a link is clickable, this is the browser's native behavior
- We should never need to test that a link opens a new tab
- In your IDE open
cypress/integration/exercise.spec.js
- Follow instructions to implement
it('link goes to ultimateqa')
test
❓What is the exact validation of this test❓
👀 Working with 'target' attribute
🏋️♀️Write a functional ui test to validate that the link opens in a new tab
- Follow instructions in this test
it('should open link in new tab')
Click here to see answer.
- Need a browser
- Need a server
- Need to deal with network issues
- Test will be slower
- Need an extra dependency (Cypress)
- Need to learn extra dependency API
Click here to see answer.
Using component tests
How to run a component test followed by How to create a test for a link
✅ E2E UI testing with Cypress allows us to do functional testing of the web app
✅ We can test a link by checking the href
attribute
✅ We can test that a url opens by checking that target='_blank'