A comprehensive Playwright test automation framework with Page Object Model (POM), utilities, data management, logging, and reporting for the SauceDemo application.
- Page Object Model (POM): Clean, maintainable page objects for all application pages
- Test Data Management: Centralized test data with user credentials and checkout information
- Advanced Logging: Detailed test execution logging with timestamps and structured output
- Custom Reporting: Comprehensive test reports with execution summaries and failure details
- Utility Functions: Helper functions for common test operations and validations
- Test Fixtures: Pre-configured test setup with authentication and page object initialization
- Screenshot Capture: Automatic screenshot capture on test failures
- Multi-Browser Support: Configured for Chromium, Firefox, and WebKit
βββ src/
β βββ pages/ # Page Object Models
β β βββ base-page.ts # Base page with common functionality
β β βββ login-page.ts # Login page object
β β βββ inventory-page.ts # Inventory/products page object
β β βββ cart-page.ts # Shopping cart page object
β β βββ checkout-page.ts # Checkout process page object
β βββ data/ # Test data management
β β βββ test-data.ts # User credentials, product info, URLs
β βββ utils/ # Utility functions
β β βββ logger.ts # Structured logging utility
β β βββ helpers.ts # Helper functions and validations
β β βββ reporter.ts # Custom test reporting
β βββ fixtures/ # Test setup and configuration
β βββ test-setup.ts # Extended test fixtures and hooks
βββ tests/ # Test specifications
β βββ saucedemo-e2e.spec.ts # Complete E2E test suite
βββ test-results/ # Test execution results
β βββ screenshots/ # Failure screenshots
βββ test_scenarios/ # BDD feature files
β βββ 01_saucedemo.feature # Original scenario definition
βββ playwright.config.ts # Playwright configuration
-
Clone the repository
git clone <repository-url> cd playwright-mcp-two
-
Install dependencies
npm install
-
Install Playwright browsers
npx playwright install
npx playwright testnpx playwright test tests/saucedemo-e2e.spec.tsnpx playwright test --headednpx playwright test --project=chromium
npx playwright test --project=firefox
npx playwright test --project=webkitnpx playwright test --grep "Complete end-to-end shopping flow"npx playwright test --debugnpx playwright show-reportThe framework includes comprehensive test coverage for:
- Login with valid credentials
- Navigate to product inventory
- Add backpack product to cart
- Proceed through checkout process
- Fill shipping information
- Complete order placement
- Verify order completion
- Test with different user types (standard, locked-out)
- Negative testing with invalid credentials
- Error message validation
- Verify product listings
- Validate product pricing
- Product detail verification
- Add/remove items from cart
- Cart quantity validation
- Continue shopping functionality
- Form validation
- Order summary verification
- Price calculation validation
The framework uses structured test data located in src/data/test-data.ts:
- User Credentials: Valid and invalid user accounts
- Product Information: Product details with prices and descriptions
- Checkout Data: Shipping information for testing
- URLs: Application endpoints and navigation paths
- Error Messages: Expected error messages for validation
- Structured Logging: Timestamped logs with log levels (INFO, ERROR, WARN, DEBUG)
- Test Steps: Clear step-by-step execution tracking
- Success/Failure Indicators: Visual indicators for test results
- Page Object Logging: Automatic logging in all page object interactions
- Test Summary: Pass/fail statistics and execution time
- Detailed Results: Individual test results with duration and errors
- Failure Screenshots: Automatic screenshot capture on failures
- HTML Reports: Built-in Playwright HTML reporting
- Maintainability: Changes to UI elements require updates in only one place
- Reusability: Page objects can be reused across multiple tests
- Readability: Tests are more readable and focused on business logic
- Accessibility-First: Uses semantic locators (getByRole, getByLabel) for better reliability
- Pre-authenticated Sessions: Automatic login setup for tests that require authentication
- Test Fixtures: Custom fixtures for page objects and common test data
- Global Hooks: Setup and teardown operations for test environment
- Error Handling: Comprehensive error handling with detailed logging
- Price Extraction: Parse and validate monetary values
- Random Data Generation: Generate test data dynamically
- Screenshot Management: Organized screenshot capture and storage
- Validation Helpers: Email, postal code, and other format validations
The framework is configured via playwright.config.ts with:
- Multi-browser support: Chromium, Firefox, WebKit
- Retry logic: 2 retries on CI, 0 locally
- Timeout settings: Reasonable timeout values for reliability
- Trace collection: On retry for debugging failures
- HTML reporting: Detailed test reports with visual timeline
The framework follows Playwright and testing best practices:
- Accessibility-First Locators: Uses getByRole, getByLabel over CSS selectors
- Web-First Assertions: Auto-retrying assertions that wait for conditions
- Test Independence: Each test can run independently without affecting others
- Descriptive Test Names: Clear test descriptions that explain the scenario
- Step Organization: Tests organized with test.step() for better reporting
- Error Screenshots: Automatic failure documentation
- Structured Logging: Comprehensive logging for debugging and monitoring
To add new test scenarios:
- Create Page Objects: Add new page objects in
src/pages/ - Add Test Data: Update
src/data/test-data.tswith new test data - Write Tests: Create new test files in
tests/directory - Update Fixtures: Add new fixtures in
src/fixtures/test-setup.tsif needed
import { test, expect } from '../src/fixtures/test-setup';
import { TestData } from '../src/data/test-data';
test.describe('My New Feature', () => {
test('should perform specific action', async ({
loginPage,
inventoryPage,
logger
}) => {
const credentials = TestData.getStandardUser();
await test.step('Login to application', async () => {
await loginPage.navigateToLoginPage(TestData.URLS.BASE_URL);
await loginPage.login(credentials.username, credentials.password);
await inventoryPage.verifyInventoryPageLoaded();
});
// Additional test steps...
});
});- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the ISC License.
Generated from SauceDemo scenario using systematic website exploration and following Playwright MCP best practices.