This project demonstrates a sample End-to-End (E2E) testing using Cypress against a live React e-commerce application: React Shopping Cart. Note that tests might fail due to changes made to test website.
It includes:
- E2E UI automation
- API stubbing with
cy.intercept() - Dynamic content handling
- Custom Cypress commands
- Clean project structure
- Cypress v13+
- JavaScript (ES6)
- Mochawesome Reports (optional)
cypress-reactshop-tests/
├── cypress/
│ ├── e2e/
│ │ ├── login.cy.js
│ │ ├── checkout_flow.cy.js
│ │ └── product_api_stubbing.cy.js
│ ├── fixtures/
│ │ └── users.json
│ └── support/
│ ├── commands.js
│ └── e2e.js
├── cypress.config.js
├── package.json
├── package-lock.json
├── .gitignore
└── README.md
- Clone the repository:
git clone https://github.com/Artenes/cypress-reactshop-tests.git
cd cypress-reactshop-tests- Install dependencies:
npm install- Open Cypress Test Runner:
npx cypress open- Run tests through the Cypress UI.
npx cypress openSelect "E2E Testing", choose your browser, and pick a spec file to run.
npx cypress runRun a specific test file:
npx cypress run --spec "cypress/e2e/login.cy.js"- Login Test (
login.cy.js): Load site, basic homepage validations - Checkout Flow Test (
checkout_flow.cy.js): Add products to cart, simulate checkout - API Stubbing Test (
product_api_stubbing.cy.js): Mock server response for products usingcy.intercept()
If you have Mochawesome installed, Cypress will generate a beautiful HTML report after running tests.
To install:
npm install --save-dev mochawesome mochawesome-merge mochawesome-report-generator cypress-mochawesome-reporterReports are generated automatically under the reports/ folder.
- Custom Cypress Commands (
cy.login,cy.addProductToCart) - API Interception and Response Mocking
- Add visual testing (e.g., Percy, Happo)
- Expand API failure simulation scenarios
- Set up GitHub Actions for automatic Cypress runs on every pull request
Artenes Junior Gomes Nogueira
- GitHub: https://github.com/Artenes
- LinkedIn: https://linkedin.com/in/artenes
This project is licensed under the MIT License.