A comprehensive end-to-end testing suite for e-commerce applications using Cypress with Page Object Model design pattern. This project demonstrates professional test automation patterns including component testing, smoke testing, and complete user journey validation.
Application Under Test: demo.codenbox.com
- Overview
- Features
- Project Structure
- Prerequisites
- Installation
- Configuration
- Running Tests
- Test Scenarios
- Page Object Model
- Best Practices
- Troubleshooting
- Author
This testing suite automates the complete e-commerce user journey from product discovery to checkout, demonstrating professional test automation patterns with Page Object Model architecture.
- ✅ Page Object Model (POM) - Clean separation of concerns
- ✅ Custom Commands - Reusable authentication and utility functions
- ✅ Environment Variables - Credentials not committed to repo
- ✅ Component Testing - Individual UI element validation
- ✅ E2E Smoke Tests - Complete purchase flow validation
- ✅ Test Data Fixtures - Maintainable test data
- ✅ Video Recording - Automatic recording of test runs
- ✅ Screenshot on Failure - Easy debugging
cypress-ecommerce-testing/
├── cypress/
│ ├── e2e/
│ │ └── ecommerce-smoke.cy.js # Main test suite
│ ├── fixtures/
│ │ └── testData.json # Test data
│ ├── support/
│ │ ├── commands.js # Custom commands
│ │ └── e2e.js # Global config
│ ├── PageObject/
│ │ ├── BasePage.js # Base class
│ │ ├── pages/
│ │ │ ├── HomePage.js
│ │ │ ├── Single_ProductPage.js
│ │ │ ├── CheckoutPage.js
│ │ │ └── LoginPage.js
│ │ └── components/
│ │ └── Navbar.js # Navigation component
│ ├── videos/ # Test recordings
│ └── screenshots/ # Failure captures
├── cypress.config.js # Cypress configuration
├── cypress.env.json.example # Credential template
├── package.json
├── .gitignore
└── README.md
- Node.js (v18 or higher)
- npm or yarn
- Modern web browser (Chrome, Firefox, Edge)
# Verify installations
node --version
npm --versiongit clone https://github.com/tyraelw/cypress-ecommerce-testing.git
cd cypress-ecommerce-testingnpm install# Copy the example file
cp cypress.env.json.example cypress.env.jsonEdit cypress.env.json with your test credentials:
{
"defaultEmail": "your-test-email@example.com",
"defaultPassword": "your-test-password",
"invalidEmail": "invalid@example.com",
"invalidPassword": "wrongpassword"
}| Variable | Description | Example |
|---|---|---|
| defaultEmail | Valid login email | user@example.com |
| defaultPassword | Valid password | TestPass123! |
| invalidEmail | Invalid email for negative tests | wrong@test.com |
| invalidPassword | Invalid password | wrongpass |
Key settings in cypress.config.js:
- Base URL: https://demo.codenbox.com
- Viewport: 1280x720 (desktop)
- Default Timeout: 8000ms
- Video Recording: Enabled
npm run cy:openBest for:
- Test development
- Debugging
- Visual inspection
# Run all tests
npm run cy:run
# Run in specific browser
npm run cy:run:chrome
npm run cy:run:firefox
npm run cy:run:edgenpm run cy:run:smokeObjective: Validate individual UI components
it('Component test', function () {
Navbar.searchProduct('MacBook')
Navbar.validateAllSearchResults('MacBook')
Navbar.clickOnMyAccount()
Navbar.clickOnLogin()
Navbar.clickOnLogo()
})Validations:
- ✅ Search functionality
- ✅ Search results accuracy
- ✅ Navigation menu
- ✅ Logo redirect
Objective: Complete user purchase journey
Test Flow:
-
Product Discovery 🔍
- Verify 4 products displayed
- Filter by name
- Navigate to details
-
Product Validation ✅
- Validate name: "MacBook"
- Validate price: "$602.00"
- Check description
-
Review Submission ⭐
- Fill review form
- Submit 5-star rating
- Validate success message
-
Cart Operations 🛒
- Add to cart
- Verify quantity and price
- Navigate to checkout
-
Authentication 🔐
- Negative Test: Invalid credentials
- Positive Test: Valid login
-
Order Validation ✨
- Verify checkout page
- Validate totals
Total Validations: 20+ assertions per run
BasePage (Parent)
├── HomePage
├── Single_ProductPage
├── CheckoutPage
├── LoginPage
└── Navbar (Component)
import BasePage from '../BasePage'
export default class HomePage extends BasePage {
static displayProducts() {
return cy.get('.product-layout')
}
static selectProducts(productName) {
this.displayProducts()
.contains(productName)
.click()
}
}Located in cypress/support/commands.js:
| Command | Description | Usage |
|---|---|---|
| openLoginPage() | Navigate to login | cy.openLoginPage() |
| login(email, password) | Successful login | cy.login() |
| loginShouldFail() | Invalid login | cy.loginShouldFail() |
| isVisible(selector) | Check visibility | cy.isVisible('.alert') |
- ✅ Environment variables for credentials
- ✅ .gitignore prevents exposure
- ✅ Template file for easy setup
- ✅ Page Object Model pattern
- ✅ DRY principle
- ✅ Reusable custom commands
- ✅ Separated test data
- ✅ Explicit waits
- ✅ Proper selectors
- ✅ Clean state between tests
- ✅ Video recording
- ✅ Screenshots on failure
- ✅ Descriptive test names
Issue: Tests fail with "defaultEmail is not defined"
Solution: Create cypress.env.json with your credentials
cp cypress.env.json.example cypress.env.json
# Edit with your test account detailsIssue: Login button not found
Solution: The site may have changed. Update selector in commands.js
Issue: Tests timeout
Solution: Increase timeout in cypress.config.js:
defaultCommandTimeout: 10000Isrrael Andres Toro Alvarez
- GitHub: @tyraelw
- LinkedIn: Isrrael Toro Alvarez
- Email: tyrael78w@gmail.com
For questions or feedback: tyrael78w@gmail.com
- Trello API Testing - REST API automation with Postman
- Grocery Store API - E-commerce API testing
⭐ If you find this project helpful, please consider giving it a star!