✅How to test a web application with functional browser tests (aka E2E tests)
- Stop all servers from previous session (
Ctrl + C
everything) - cd
testing-for-charity/my-react-app
npm install && npm start
Open application at http://localhost:3000/
- How about a functional browser test sure that our app renders?
"Fast, easy and reliable testing for anything that runs in a browser."(Cypress.io)
cd testing-for-charity/my-react-app
npx cypress open
💡 Tests live in cypress/integration
folder
- In your IDE open
cypress/integration/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');
})
- 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')
- 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
✅E2E UI testing with Cypress allows us to do functional testing of the web app
✅However, it's inneficient and there are better alternatives