UI test suite for SauceDemo – a sample e-commerce website by SauceLabs for practicing test automation. This project provides UI tests implemented with Playwright and pytest.
- Current version: 0.1.0
- Detailed release notes: see
RELEASE.md
# Install dependencies
make install
# Install Playwright browsers
make install-browsers
# Run tests in headless mode
make test
# Run tests in UI mode (visible browser)
make test-ui
# Run tests with HTML report
make test-htmlCore packages:
pytest- testing frameworkplaywright- browser automationpytest-playwright- Playwright integration for pytestfaker- test data generationpytest-html- HTML reports with logspython-dotenv- environment configurationuv- Python package manager
Development tools:
ruff- linter and formatter (replaces flake8 + black + isort)
Page Object Model implementation - each page has its own class:
base_page.py- base class with common Playwright methodslogin_page.py- login page interactionsinventory_page.py- product catalog pageproduct_page.py- individual product detailscart_page.py- shopping cartcheckout_page.py- checkout formoverview_page.py- order overvieworder_page.py- order confirmation
logger.py- custom logger for test execution (saves to files + outputs to HTML report)generator.py- test data generation via Faker
tests_data.py- test credentials, URLs, and expected messages
page_locators.py- Playwright CSS selectors for page elements
conftest.py- pytest fixtures (Playwright page setup, page objects, logging)test_base.py- base test class (BaseTest) that all test classes inherit fromtest_*.py- test suites for each module
Uses pytest fixtures for test environment setup:
page- Playwright Page object with browser (provided by pytest-playwright)pages- page objects accessible across testsdata- Faker-based data generatorlog_test_execution- automatic test logging
All test classes inherit from BaseTest (in test_base.py), which automatically injects pages and data fixtures into test instances via the injector fixture.
Clean separation of test logic from page interactions:
- Locators stored separately in
locators/page_locators.py(CSS selectors) - Reusable actions in base page class
- Business logic methods in specific page classes
- File logging: detailed test execution logs in
logs/test_run_*.logwith test separators - HTML reports: test logs displayed in pytest-html reports
- Console output: real-time test execution info
Playwright browser configured with:
- Support for headless and UI modes
- Optimized viewport size (1920x1080)
- Disabled automation detection
- Optimized for CI/CD environments
- Locators: Uses CSS selectors instead of XPath tuples
- Browser Management: Playwright handles browser lifecycle automatically
- Waits: Built-in auto-waiting, no explicit WebDriverWait needed
- Performance: Generally faster execution than Selenium
- API: More modern and Pythonic API
Project uses Ruff - a fast Rust-based linter that replaces flake8, black, isort and other tools.
# Check code
make lint
# Auto-fix issues
make fix
# Format code
make format
# Check formatting
make format-checkRuff is configured with rules:
- pycodestyle (E, W)
- pyflakes (F)
- isort (I)
- pep8-naming (N)
- pyupgrade (UP)
- flake8-bugbear (B)
- flake8-comprehensions (C4)
- flake8-simplify (SIM)
HTML Reports (reports/test_report.html):
- Test execution summary
- Detailed logs for each test
- Pass/fail status and duration
- Environment metadata
File Logs (logs/test_run_*.log):
- Complete test execution logs
- Timestamps for each action
- Test separators for easy navigation
- DEBUG level details for troubleshooting
Generated HTML report (reports/test_report.html) provides a comprehensive view of test execution:
The report includes:
- Test execution summary with pass/fail statistics
- Environment details (Python version, platform, packages)
- Detailed logs for each test with timestamps
- Expandable test details for troubleshooting
Each test execution is logged with detailed step-by-step information in logs/test_run_*.log:
================================================================================
Starting test: test_open_cart
Test parameters: {'username': 'standard_user', 'password': '***'}
================================================================================
2025-11-14 17:04:42 - LoginPage - INFO - Opening login page
2025-11-14 17:04:42 - LoginPage - INFO - Opening base URL: https://www.saucedemo.com/
2025-11-14 17:04:45 - LoginPage - INFO - Login attempt: standard_user
2025-11-14 17:04:45 - LoginPage - INFO - Entering username: standard_user
2025-11-14 17:04:45 - LoginPage - INFO - Entering password: ************
2025-11-14 17:04:45 - LoginPage - INFO - Clicking login button
2025-11-14 17:04:46 - tests.test_cart - INFO - Assertion: Expected='Your Cart', Actual='Your Cart' - Cart title validation
2025-11-14 17:04:46 - tests.test_cart - INFO - Assertion: Expected='https://www.saucedemo.com/cart.html', Actual='https://www.saucedemo.com/cart.html' - Cart URL validation
================================================================================
Test test_open_cart PASSED
================================================================================
Each log entry includes:
- Timestamp for precise tracking
- Component name (e.g., LoginPage, CartPage)
- Log level (INFO, DEBUG, WARNING, ERROR)
- Action description with relevant parameters
- Assertion validations with expected vs actual values
- Test result status (PASSED/FAILED)
Configuration via environment variables in .env:
HEADLESS- browser mode (headlessorui)
- 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)
Total: 34 tests covering main e-commerce scenarios.
Project is containerized for consistent test execution:
# Build image
make docker-build
# Run tests in Docker (headless)
make docker-test
# Run tests in Docker with HTML report
make docker-test-html
# Open shell in container
make docker-shell
# Clean up Docker resources
make docker-cleanDockerfile uses Python 3.11 slim image and Playwright with Chromium for stable test execution.
make install # Install dependencies with uv (including dev tools)
make install-browsers # Install Playwright browsersmake test # Run test suite (headless)
make test-ui # Run tests in UI mode (visible browser)
make test-headless # Run tests in headless mode
make test-html # Run tests and generate HTML report
make all # Install, format, lint, and test (full workflow)make lint # Run Ruff lint checks
make format # Format code with Ruff
make format-check # Check formatting without modifying files
make fix # Auto-fix lint issues and format codemake docker-build # Build Docker image
make docker-test # Run tests in Docker (headless)
make docker-test-html # Run tests in Docker with HTML report
make docker-shell # Open shell in Docker container
make docker-clean # Remove Docker containers and imagesmake clean # Remove cache artifacts, reports, and logs
make help # Show all available commandsWebsite Under Test: https://www.saucedemo.com
