-
Clone the repository:
git clone https://github.com/DanailZahariev/saucedemo-pom-playwright.git
-
Install project dependencies (including Allure CLI):
npm install
-
Install Playwright browsers:
npx playwright install
- Language: TypeScript
- Framework: Playwright Test
- Design Pattern: Page Object Model (POM) + Playwright Fixtures
- Reporting: Allure Report & Playwright HTML
- Environment: Node.js
The project follows the Page Object Model (POM) design pattern, optimized with Playwright Fixtures for Dependency Injection, and a dedicated Data Layer for type safety.
.
├── fixtures/ # Playwright Fixtures for Dependency Injection
│ └── fixtures.ts # Custom test object extending base pages
├── page-objects/ # Page Object Model (POM) Implementation
│ ├── auth/ # Login & Authentication pages
│ ├── base/ # BasePage with common wrapper methods (SOLID)
│ ├── cart/ # Cart functionality and logic
│ ├── checkout/ # Checkout process steps
│ ├── inventory/ # Inventory list and product filtering
│ ├── product/ # Product details page logic
│ └── pageManager.ts # ⚡ Manager for Lazy Loading of page objects
│
├── test-data/ # Data Layer (Type-Safe)
│ ├── enums/ # TypeScript Enums (e.g., SortOption)
│ ├── models/ # Interfaces for Users and Products
│ ├── products.json # Raw product data (JSON)
│ ├── users.json # Raw user data (JSON)
│ └── testData.ts # Centralized, typed data export
│
├── tests/ # Test Specifications (*.spec.ts)
├── playwright-report/ # Test execution reports (HTML)
├── playwright.config.ts # Playwright Configuration
└── package.json # Dependencies and Scripts
We use NPM scripts to simplify test execution and report generation.
Execute all .spec.ts files in headless mode (this automatically generates raw Allure results):
npm run test(Optional) Run with UI Mode for debugging and time-travel execution:
npx playwright test --uiThis framework is configured with Allure Reports for rich, interactive test results.
- Clear old results (recommended before a new run):
npm run allure:clear
- Generate the HTML report from raw results:
npm run allure:generate
- Open and view the report in your browser:
npm run allure:open
The framework covers core End-to-End user journeys using data from the test-data directory:
- Login with a valid user (standard_user).
- Error validation for invalid credentials or locked-out users.
- Sorting products (by name or price).
- Viewing product details.
- Adding products to the cart directly from the inventory list.
- Adding Items: Verifying the cart badge updates correctly.
- Removing Items: Removing items and validating the list count.
- Price Consistency: Ensuring the price displayed in the inventory matches the price in the cart.
- Navigation: Verifying that "Continue Shopping" preserves the cart state.
- Filling out shipping information (First Name, Last Name, Zip Code).
- Validating the Summary page before finishing.
- Completing the order successfully.
- Playwright Fixtures (Dependency Injection): Instead of using a bulky
PageManageror instantiating page objects manually in every test, the framework uses Playwright'sfixtures. This ensures true lazy-loading, automatic setup/teardown, and keeps test specifications highly declarative and readable.// Example: Injecting exactly the pages needed for the test test('Add item to cart', async ({ loginPage, inventoryPage }) => { await loginPage.goto(); // ... });
- Accessibility-First Locators: The framework prioritizes user-facing locators (
getByRole,getByText,getByPlaceholder) anddata-testattributes over brittle CSS selectors, ensuring robust and standard-compliant automation. - Data-Driven Testing: User credentials and product details are not hardcoded. They are imported from JSON files (
users.json,products.json), making updates and maintenance much easier.
This project includes a GitHub Actions workflow to automatically run tests on every push or pull request to the main
or master branches.
The workflow is defined in .github/workflows/playwright.yml and performs the following steps:
- Sets up a Linux environment (Ubuntu).
- Installs Node.js and dependencies.
- Installs Playwright browsers.
- Executes the tests.
- Uploads the HTML report as an artifact (retained for 30 days).