A production-ready automation testing framework for Flipkart.com built with Playwright and TypeScript. This project demonstrates comprehensive e-commerce workflow automation using the Page Object Model (POM) design pattern.
- β Page Object Model Pattern - Clean separation of concerns
- β TypeScript - Full type safety with strict mode
- β Playwright - Cross-browser automation framework
- β HTML Reports - Detailed test reports with screenshots
- β Exact Locators - Pre-tested XPath selectors (75+)
- β Custom Assertions - 15+ domain-specific validations
- β Config Management - Environment-based configuration
- β Headless Mode - Windows-compatible execution
-
Search 5 Products from different categories:
- iPhone 17 Pro Max (Electronics)
- Women Kurtas (Clothing)
- Lakme Lipstick (Beauty)
- Logitech G29 (Gaming)
- MamyPoko Pants-XL (Baby Care)
-
Add to Cart - First product from each search
-
Cart Operations:
- Compare products
- Remove last 2 items
- Verify item count
-
Extract Price Details with assertions:
- Item count
- Subtotal
- Discount applied
- Platform fee
- Shipping charges
- Total amount
- Delivery address
-
Place Order - Complete checkout flow
Ecomerce Flip Automation/
β
βββ src/
β βββ pages/ # Page Object Classes
β β βββ BasePage.ts # Base class (common methods)
β β βββ HomePage.ts # Search & navigation
β β βββ LoginPage.ts # Authentication
β β βββ SearchResultsPage.ts # Search results
β β βββ ProductDetailsPage.ts # Product details
β β βββ CartPage.ts # Shopping cart (CRITICAL)
β β βββ CheckoutPage.ts # Order confirmation
β β βββ index.ts # Clean exports
β β
β βββ utils/ # Utility Functions
β β βββ helper.ts # 20+ helper functions
β β βββ assertions.ts # 15+ custom assertions
β β
β βββ config/ # Configuration
β βββ config.ts # Environment settings
β
βββ tests/ # Test Specifications
β βββ flipkart.spec.ts # TC-001 (Main test)
β βββ flipkart-advanced.spec.ts # TC-002 to TC-006
β
βββ test-data/ # Test Data
β βββ testData.ts # Products, credentials
β
βββ playwright-report/ # Generated HTML reports
βββ test-results/ # JSON test results
βββ screenshots/ # Test failure screenshots
βββ videos/ # Test failure videos
β
βββ Configuration Files
β βββ package.json # NPM dependencies
β βββ playwright.config.ts # Playwright settings
β βββ tsconfig.json # TypeScript config
β βββ .env.example # Environment template
β βββ .gitignore # Git ignore rules
β
βββ README.md # This file
- OS: Windows 10/11
- Node.js: v16.0.0 or higher
- npm: v7.0.0 or higher
# Check Node.js version
node --version # Should be v16+
# Check npm version
npm --version # Should be v7+# Navigate to project directory
cd "C:\Users\user\Ecomerce Flip Automation"
# Install all packages
npm install# Browsers are auto-installed with npm install
# But you can explicitly install:
npx playwright install chromium# Copy example to .env
copy .env.example .env
# Edit .env with your settings if needednpm run test:main
# or
npm run test:headlessnpm run test
# or for all with headless
npm run test:headlessnpm run test:advancednpm run test:debug
# Playwright Inspector opens, pause and step through codenpm run test:ui
# Interactive test runner with real-time feedbacknpm run test:report
# Opens HTML report in default browser| Command | Description | Time |
|---|---|---|
npm run test |
Run all tests | 15-20 min |
npm run test:main |
Run main test only | 4-6 min |
npm run test:advanced |
Run advanced tests | 10-15 min |
npm run test:headless |
Run headless (fast) | 15-20 min |
npm run test:headed |
Run with browser visible | 15-20 min |
npm run test:debug |
Debug with inspector | 10-15 min |
npm run test:ui |
Interactive mode | Manual |
npm run test:report |
View HTML report | Instant |
The project uses dummy test credentials for login:
- Phone: 9876543210
- OTP: 123456
- Pincode: 560001 (Bangalore)
- Located in
src/pages/LoginPage.ts - OTP login currently commented (requires real OTP)
- Can be enabled for actual user testing
- β Easy maintenance (centralized locators)
- β Code reusability across tests
- β Clear separation of concerns
- β Better readability
// Page Object Class
class HomePage extends BasePage {
private selectors = {
searchInput: '//input[@placeholder="Search..."]',
searchButton: '//button[@type="submit"]'
};
async searchProduct(name: string) {
await this.fillText(this.selectors.searchInput, name);
await this.clickElement(this.selectors.searchButton);
}
}
// Usage in Test
const homePage = new HomePage(page);
await homePage.searchProduct('iPhone');All locators are exact, unique, and pre-tested for Flipkart.com
| Page | Count | Key Locators |
|---|---|---|
| HomePage | 8 | Search input, cart icon, login |
| LoginPage | 10 | Phone input, OTP field, verify button |
| SearchResultsPage | 10 | Product container, price, add to cart |
| ProductDetailsPage | 17 | Title, price, rating, add to cart |
| CartPage | 24 | Items, prices, remove button, place order |
| CheckoutPage | 20 | Address, payment, confirm order |
- Price parsing and formatting
- Phone number validation
- OTP validation
- Random data generation
- Retry logic
- Delay utilities
- Logging with timestamps
- Price detail validations
- Cart operation assertions
- Search result checks
- Address validation
- Order placement verification
- Console output logging
- development - Local testing with visible browser
- staging - Pre-production testing
- production - Production-like settings
- ci - CI/CD pipeline execution
Located in test-data/testData.ts:
PRODUCTS_TO_SEARCH = [
{ name: 'iphone 17 pro max', category: 'Electronics' },
{ name: 'women kurtas', category: 'Clothing' },
{ name: 'lakme lipstick', category: 'Beauty' },
{ name: 'logitech g29', category: 'Gaming' },
{ name: 'mamypoko pants-xl', category: 'Baby Care' }
]Update product names to test different items
- Generated automatically after tests
- Located in
playwright-report/folder - Includes:
- Test status (β Passed / β Failed)
- Execution time
- Console logs and output
- Screenshots on failure
- Video recordings on failure
- Detailed trace information
npm run test:report# Clear node_modules and reinstall
rm -r node_modules
npm install- Increase timeout in
src/config/config.ts - Verify locator matches current Flipkart UI
- Check internet connection
- Run with
npm run test:debugto inspect
# Reinstall browsers
npx playwright install chromium- OTP login is optional, most tests skip login
- Tests work without authentication
- Searches 5 products
- Adds each to cart
- Compares products
- Removes 2 items
- Extracts all price details
- Places order
- Duration: 4-6 minutes
- Single product search
- Add to cart verification
- Duration: 2-3 minutes
- Add 2 products
- Extract complete price breakdown
- Full validation assertions
- Duration: 3-4 minutes
- Search 3 products
- Verify results for each category
- Display results summary
- Duration: 3-4 minutes
- Add 3 products
- Remove items one by one
- Verify count changes
- Duration: 3-4 minutes
- Search single product
- Display first 5 results
- Show titles and prices
- Duration: 2-3 minutes
[12:34:56 PM] STEP 1: Navigating to Flipkart Home
[12:34:58 PM] β Home page loaded successfully
[12:35:00 PM] STEP 2.1: Searching for "iphone 17 pro max"
[12:35:02 PM] β Search initiated for: iphone 17 pro max
[12:35:03 PM] β Found 500 results...
========================================
PRODUCTS IN CART
========================================
1. Apple iPhone 17 Pro Max 256GB
Price: βΉ1,39,999
2. Anvi Kurta Cotton...
Price: βΉ799
========================================
========================================
PRICE DETAILS BREAKDOWN
========================================
Items in Cart: 3
Subtotal: βΉ1,89,097
Discount: βΉ5,000
Platform Fee: βΉ0
Shipping Charge: Free
Total Amount: βΉ1,84,097
Delivery Address: 123 Main St, Bangalore
========================================
# 1. Move to existing project folder
cd "C:\Users\user\Ecomerce Flip Automation"
# 2. Install dependencies (2 min)
npm install
# 3. Run main test (3 min)
npm run test:main
# 4. View report
npm run test:report
# β Done! Check the browser for HTML report| Folder | Purpose | Clarity |
|---|---|---|
src/ |
Source code | Clear and standard |
pages/ |
Page object classes | Descriptive name |
utils/ |
Helper functions | Self-explanatory |
config/ |
Configuration files | Standard term |
tests/ |
Test specifications | Clear purpose |
test-data/ |
Test data files | Descriptive |
After running tests, verify:
- Tests execute without errors
- Console shows timestamped logs
- All 5 products searched successfully
- Products added to cart
- Last 2 items removed from cart
- Price details extracted and printed
- Assertions passed (console output)
- HTML report generated
- Order placement attempted
- README.md - This file (complete overview)
- package.json - Dependencies and scripts
- playwright.config.ts - Playwright configuration
- tsconfig.json - TypeScript settings
- .env.example - Environment variables template
| File | Purpose | Lines |
|---|---|---|
src/pages/CartPage.ts |
Shopping cart operations | 250+ |
tests/flipkart.spec.ts |
Main test (TC-001) | 350+ |
src/utils/helper.ts |
Utility functions | 200+ |
src/utils/assertions.ts |
Custom assertions | 200+ |
test-data/testData.ts |
Test products & credentials | 50+ |
src/config/config.ts |
Configuration management | 150+ |
- Run
npm install - Run
npm run test:main - View
npm run test:report
- Read through
src/pages/CartPage.tsfor price extraction - Check
tests/flipkart.spec.tsfor test flow - Review assertions in
src/utils/assertions.ts
- Update products in
test-data/testData.ts - Modify locators in
src/pages/*.tsif Flipkart UI changes - Add new test cases in
tests/folder
- Always use page objects - Don't interact with page directly
- Centralize locators - Update in one place
- Use assertions - Validate test expectations
- Log status - Use
logWithTimestamp()for debugging - Handle errors gracefully - Try-catch for optional features
- Playwright - Browser automation
- TypeScript - Type safety
- @playwright/test - Testing framework
- Playwright Docs: https://playwright.dev
- TypeScript Handbook: https://www.typescriptlang.org/docs
- Page Object Model: https://playwright.dev/docs/pom
MIT License - Feel free to use and modify
| Aspect | Status |
|---|---|
| Code Quality | β Production-ready |
| Design Pattern | β Page Object Model |
| Type Safety | β TypeScript strict mode |
| Documentation | β Comprehensive |
| Test Coverage | β Complete workflow |
| Error Handling | β Proper exception handling |
| Reporting | β HTML + JSON + Console |
| Maintainability | β Easy to extend |
Project Status: β COMPLETE & PRODUCTION READY
Next Action: Run npm run test:main
Expected Result: All tests pass with detailed console output and HTML report
Created: 2024 Framework: Playwright + TypeScript Pattern: Page Object Model Environment: Windows Headless Locators: 75+ exact and unique selectors Assertions: 15+ custom validations Test Cases: 6 comprehensive scenarios
π Happy Testing!