SauceDemo UI Tests with Playwright¶
A UI test suite for SauceDemo, a sample e-commerce website by SauceLabs for practicing test automation. It is built with Playwright and pytest and covers the main shopping flow, from login to order confirmation, with 34 tests, detailed logs and HTML reports.
What's Covered¶
- Login — 7 tests: valid/invalid credentials, locked user, logout, error handling
- Inventory — 8 tests: menu links, purchases, sorting, add to cart
- Product — 4 tests: navigation, add to cart, remove from cart
- Cart — 3 tests: add/remove items, continue shopping
- Checkout — 7 tests: form validation, cancel, complete flow
- Overview — 3 tests: order review, cancel, finish
- Order — 2 tests: confirmation page, back to products
How It's Built¶
- Page Object Model with inheritance —
BasePage → LoginPage → InventoryPage → specific pages, with locators kept separately inlocators/page_locators.py. - Playwright built-in locators —
get_by_test_id,get_by_role,get_by_placeholder, withdata-testset as the test ID attribute. - Rich assertions — helper methods in the base page plus Playwright
expectassertions with auto-retry. - Fixture-based setup — pytest fixtures configure the browser and expose page objects and a Faker data generator; a
BaseTestclass injects them into every test class. - Dual logging — step-by-step file logs in
logs/, console output and logs embedded in the pytest-html report. - Docker — a headless
testsservice for CI/CD and atests-uiservice with X11 forwarding for visual debugging.
Tech Stack¶
pytest— testing frameworkplaywright— browser automationpytest-playwright— Playwright integration for pytestfaker— test data generationpytest-html— HTML reports with logspython-dotenv— environment configurationuv— Python package managerruff— linter and formatter
Running It¶
Install dependencies and browsers, create .env, then run the tests:
make install
make install-browsers
make env
make test