This project demonstrates end-to-end test automation for the Sauce Demo e-commerce website using Cypress. The test suite covers the complete purchase flow from login to order completion.
- Complete purchase flow for single product
- Complete purchase flow for multiple products
- Form validation testing (checkout information)
- Navigation testing (return to products after purchase)
SauceLabAutomation/
├── cypress/
│ ├── e2e/
│ │ └── purchase.cy.js # Main E2E test suite
│ ├── fixtures/
│ │ └── testData.json # Test data (credentials, checkout info)
│ ├── support/
│ │ ├── commands.js # Custom Cypress commands
│ │ ├── e2e.js # Support file
│ │ ├── pages/ # Page Object Models (Actions)
│ │ │ ├── LoginPage.js
│ │ │ ├── ProductsPage.js
│ │ │ ├── CartPage.js
│ │ │ ├── CheckoutPage.js
│ │ │ ├── CheckoutOverviewPage.js
│ │ │ └── CheckoutCompletePage.js
│ │ ├── locators/ # Page Locators (Selectors)
│ │ │ ├── LoginPageLocators.js
│ │ │ ├── ProductsPageLocators.js
│ │ │ ├── CartPageLocators.js
│ │ │ ├── CheckoutPageLocators.js
│ │ │ ├── CheckoutOverviewPageLocators.js
│ │ │ └── CheckoutCompletePageLocators.js
│ │ └── assertions/ # Page Assertions (Validations)
│ │ ├── LoginPageAssertions.js
│ │ ├── ProductsPageAssertions.js
│ │ ├── CartPageAssertions.js
│ │ ├── CheckoutPageAssertions.js
│ │ ├── CheckoutOverviewPageAssertions.js
│ │ └── CheckoutCompletePageAssertions.js
├── cypress.config.js # Cypress configuration
├── package.json
└── README.md
- Node.js (v14 or higher)
- npm or yarn
-
Clone the repository:
git clone <your-repo-url> cd SauceLabAutomation
-
Install dependencies:
npm install
npx cypress openThis opens the Cypress UI where you can:
- Select and run individual tests
- Watch tests execute in real-time
- Debug test failures
npx cypress runThis runs all tests in headless mode and generates:
- Video recordings (saved in
cypress/videos/) - Screenshots on failure (saved in
cypress/screenshots/)
npx cypress run --spec "cypress/e2e/purchase.cy.js"npx cypress run --browser chrome
npx cypress run --browser firefox
npx cypress run --browser edgeThe framework follows a 3-layer separation pattern for maximum maintainability:
- Purpose: Centralized repository of all element selectors
- Benefits:
- Single source of truth for selectors
- Easy to update when UI changes
- Reduces duplication across tests
- Purpose: Reusable validation methods
- Benefits:
- Standardized assertion patterns
- Easy to add new validations
- Consistent error messages
- Promotes assertion reusability
- Purpose: User-facing actions and workflows
- Benefits:
- Clean, readable test code
- Encapsulates page behavior
- Easy to compose complex workflows
- Tests read like user stories
Traditional POM: Page Objects contain Locators + Actions + Assertions (tightly coupled)
Advanced 3-Layer: Locators ← Assertions ← Page Objects ← Tests (loosely coupled)
Benefits of Separation:
- UI Changes: Only update locators layer
- Assertion Changes: Only update assertions layer
- Business Logic Changes: Only update page objects layer
- Reusability: Assertions and locators shared across multiple page objects
- Testing: Each layer can be tested independently
- Scalability: Easy to add new pages without duplication
- Separation of Concerns: Page objects encapsulate page-specific selectors and actions
- Reusability: Methods can be reused across multiple test cases
- Maintainability: UI changes only require updates in one place
- Readability: Tests read like user stories
- Fixture Files: Credentials and test data stored in
testData.json - Benefits:
- Easy to update test data without touching test code
- Can easily switch between different user types
- Supports data-driven testing
Custom Cypress commands for common actions:
cy.login(username, password)- Quick logincy.addToCart(productName)- Add product to cartcy.completeCheckout(firstName, lastName, postalCode)- Fill checkout form
- Login with valid credentials
- Add one product to cart
- Verify cart badge counter
- Proceed to checkout
- Fill shipping information
- Verify order summary
- Complete purchase
- Verify order confirmation
- Login with valid credentials
- Add multiple products to cart
- Verify all products in cart
- Complete checkout process
- Verify final order includes all products
- Tests form validation for required fields
- Verifies appropriate error messages
- Verifies user can navigate back to products after completing order
- Cross-browser testing: Add parallel execution for Chrome, Firefox, Edge
- API Testing: Integrate API tests to validate backend responses
- Visual Regression Testing: Add screenshot comparison for UI consistency
- Performance Testing: Measure and assert page load times
-
Test Data Generation: Implement faker.js for dynamic test data
-
Negative Test Cases:
- Invalid login attempts
- Special characters in forms
- Boundary value testing
- Session timeout handling
-
Product Filtering/Sorting: Test product sort and filter functionality
-
Mobile Responsive Testing: Test on various viewport sizes
-
Shopping Cart Edge Cases:
- Remove items from cart
- Update quantities
- Continue shopping flow
-
CI/CD Integration:
- GitHub Actions workflow
- Azure DevOps pipeline
- Jenkins integration
-
Test Reports:
- Mochawesome HTML reports
- Allure reporting
- Dashboard integration
-
Code Coverage: Track application code coverage
-
Session Management: Test remember me functionality
-
Security Testing:
- XSS injection tests
- SQL injection tests
- Authentication bypass attempts