This project contains automated tests for demoblaze.com e-commerce website, focusing on the login and shopping cart functionality.
- Login flow validation
- Add to cart functionality testing
- Multiple product handling
- Price calculation verification
- Cart management (add/remove products)
├── tests/ # Test files │ ├── login.spec.ts # Login flow tests │ └── cart.spec.ts # Shopping cart tests ├── pages/ # Page Object Models │ ├── BasePage.ts # Base page with common functionality │ ├── LoginPage.ts # Login page interactions │ ├── ProductPage.ts # Product page interactions │ └── CartPage.ts # Cart page interactions ├── utils/ # Utility files │ └── test-data.ts # Test data (users, products) └── helpers.ts # Helper functions ├── playwright.config.ts # Playwright configuration ├── .env # Stores environment variables such as URL and credentials ├── .env.example # Template for adding your own user credentials └── package.json # Project dependencies
-
Prerequisites
- Node.js (v14 or higher)
- npm or yarn
-
Installation
# Clone this repository git clone https://github.com/asmita438/demo cd demo # Install dependencies npm install # Install browsers npx playwright install
-
Configure Environment Variables
# Copy the .env.example to .env and fill in your user credentials and site URL: cp .env.example .env
-
Running Tests
# Run all tests npm test # Run specific test files npm run test:login npm run test:cart # Run tests in headed mode (with browser visible) npm run test:headed # Debug tests npm run test:debug # View HTML report npm run report
This test suite utilizes the Page Object Model pattern to create a maintainable and scalable test framework. Key features include:
- Abstraction - Each page has its own class that represents the UI elements and actions.
- Reusability - Common methods are defined in the BasePage class.
- Maintainability - UI elements are defined in a single location.
- Readability - Test cases are written in a descriptive, easy-to-understand manner.
-
Alert Handling
- The site uses JavaScript alerts for confirmation messages which require special handling in Playwright.
- Solution: Implemented dialog listeners to automatically accept alerts.
-
Dynamic Content
- Product availability may change over time.
- Solution: Used a flexible selector approach and implemented proper waiting strategies.
-
Network Reliability
- The demo site can sometimes be slow or flaky.
- Solution: Added proper wait mechanisms and retry logic in the config.
- API Integration - Add API tests to validate backend functionality.
- Visual Testing - Implement visual regression testing.
- CI/CD Integration - Set up GitHub Actions workflow.
- Data-driven Testing - Extend test coverage with more varied test data.
- Performance Metrics - Add performance testing capabilities.