A comprehensive test automation framework for SauceDemo e-commerce application using Python and Playwright.
This project implements automated regression tests for SauceDemo, covering critical user flows including authentication, shopping cart operations, and checkout processes.
- Language: Python 3.9+
- Test Framework: Playwright for Python
- Test Runner: pytest
- Reporting: pytest-html
- CI/CD: GitHub Actions
assessment-swag-labs/
├── tests/ # Test suites
│ ├── test_login.py # Authentication tests
│ ├── test_cart.py # Shopping cart tests
│ ├── test_checkout.py # Checkout flow tests
│ └── conftest.py # Pytest fixtures and configuration
├── pages/ # Page Object Model classes
│ ├── login_page.py # Login page interactions
│ ├── inventory_page.py # Product listing page
│ ├── cart_page.py # Shopping cart page
│ └── checkout_page.py # Checkout pages
├── utils/ # Utility functions
│ ├── config.py # Configuration management
│ └── helpers.py # Helper functions
├── data/ # Test data
│ └── test_data.json # Test data in JSON format
├── reports/ # Test reports (generated)
├── .github/
│ └── workflows/
│ └── tests.yml # GitHub Actions CI workflow
├── pytest.ini # Pytest configuration
├── requirements.txt # Python dependencies
└── README.md # This file
- Python 3.9 or higher
- pip (Python package manager)
- Git
-
Clone the repository (if applicable):
git clone <repository-url> cd assessment-swag-labs
-
Create a virtual environment:
python -m venv .venv
-
Activate the virtual environment:
- On Linux/Mac:
source .venv/bin/activate - On Windows:
.venv\Scripts\activate
- On Linux/Mac:
-
Install dependencies:
pip install -r requirements.txt
-
Install Playwright browsers:
playwright install
-
Set up environment variables (optional):
cp .env.example .env # Edit .env file with your configuration if needed
pytest# Run only login tests
pytest -m login
# Run only cart tests
pytest -m cart
# Run only checkout tests
pytest -m checkoutpytest tests/test_login.pypytest -vpytest --headedScreenshots are automatically captured on test failures and saved in test-results/ directory.
Run the full suite on all supported browsers (Chromium, Firefox, WebKit). Each test runs once per browser:
pytest --browser chromium --browser firefox --browser webkitRun on a single browser only (e.g. for faster local feedback):
pytest --browser firefox- ✅ Valid login with correct credentials
- ✅ Invalid username
- ✅ Invalid password
- ✅ Locked out user handling
- ✅ Empty username validation
- ✅ Empty password validation
- ✅ Empty credentials validation
- ✅ Login page elements visibility
- ✅ Add single item to cart
- ✅ Add multiple items to cart
- ✅ Remove item from inventory page
- ✅ Remove item from cart page
- ✅ Cart persistence across navigation
- ✅ Cart persists after cart page refresh
- ✅ Cart badge preserved after inventory refresh
- ✅ Cart badge count updates
- ✅ Cart items display correctly
- ✅ Inventory loads with all products
- ✅ Inventory sorting by name and price
- ✅ Proceed to checkout from cart
- ✅ Inventory access in a new tab after login
- ✅ Complete end-to-end checkout flow
- ✅ Checkout form validation (missing first name)
- ✅ Checkout form validation (missing last name)
- ✅ Checkout form validation (missing postal code)
- ✅ Cancel checkout functionality
- ✅ Logout after checkout
- ✅ Checkout with multiple items
- ✅ Error message clears after fixing checkout info
- ✅ Back/forward navigation during checkout
- ✅ Overview items match cart items
- ✅ Totals and tax calculation on overview
The framework uses the Page Object Model pattern to improve maintainability and reduce code duplication:
- LoginPage: Handles all login page interactions
- InventoryPage: Manages product listing, sorting, and cart operations
- CartPage: Handles shopping cart operations
- CheckoutPage: Manages checkout information and completion
Test data is stored in data/test_data.json and includes:
- User credentials (standard, locked_out, problem, etc.)
- Customer information for checkout
- Product names
Configuration is managed through:
utils/config.py: Base URLs, credentials, timeouts.envfile: Environment-specific variables (optional)pytest.ini: Pytest configuration and markers
After test execution, HTML reports are generated in the reports/ directory:
reports/report.html: Comprehensive test report with results
Screenshots are saved in test-results/ directory on failures.
The project includes a GitHub Actions workflow (.github/workflows/tests.yml) that:
- Runs tests on push/PR to main/master/develop branches
- Uses a cross-browser matrix: the suite runs on Chromium, Firefox, and WebKit (one job per browser)
- Installs only the browser for each matrix job and runs
pytest --browser <browser> - Generates test reports and uploads artifacts per browser:
test-results-chromium,test-results-firefox,test-results-webkit(each containsreports/andtest-results/)
- Page Object Model: Separates page interactions from test logic
- Fixtures: Reusable test setup using pytest fixtures
- Data-Driven Testing: Test data externalized in JSON files
- Robust Locators: Using data-test attributes and role-based selectors
- Auto-waiting: Leveraging Playwright's built-in waiting mechanisms
- Error Handling: Comprehensive error messages and assertions
- Documentation: Clear docstrings and README
- Playwright + pytest:
- Playwright provides modern, reliable browser automation with built-in auto-waiting and powerful debugging tools.
- pytest offers a simple, expressive test syntax and rich plugin ecosystem (fixtures, markers, HTML reports).
- Page Object Model (POM):
- Pages encapsulate selectors and actions so tests focus on business flows.
- Mapping:
LoginPage→tests/test_login.pyInventoryPage→tests/test_cart.py,tests/test_checkout.pyCartPage→tests/test_cart.py,tests/test_checkout.pyCheckoutPage→tests/test_checkout.py
- Suite layering via markers:
@pytest.mark.loginfor authentication coverage.@pytest.mark.cartfor cart and inventory/cart interactions.@pytest.mark.checkoutfor checkout flows.- A subset of high-value end-to-end tests can be additionally marked as
smokefor faster CI runs.
- Rely on Playwright auto-waiting instead of arbitrary sleeps.
- Use explicit readiness checks such as:
InventoryPage.is_loaded()after login or refresh.CartPage.is_loaded()after navigating to the cart.CheckoutPage.is_step_one_loaded()andCheckoutPage.is_overview_loaded()around checkout transitions.
- For absence checks (e.g., empty cart badge), use low/zero timeouts so tests fail fast instead of waiting for the full default timeout.
- Keep tests stateless and isolated by using fresh pages/contexts via pytest fixtures.
Navigation-related scenarios covered by the suite include:
- Direct navigation to
inventory.htmlwithout login redirects back to the login page. - After logout, attempts to access
inventory.htmlare redirected to login. - Cart state persists across:
- Navigation between inventory and cart.
- Refreshing the cart page.
- Refreshing the inventory page (cart badge count preserved).
- Checkout back/forward behavior:
- From checkout step two, using browser Back returns to step one with data cleared.
- Using browser Forward returns to step two with overview still loaded.
- Logged-in users can open
inventory.htmlin a new tab and remain authenticated.
Potential improvements for the framework:
- API testing integration
- Performance testing
- Visual regression testing
- Cross-browser testing matrix
- Test data generation utilities
- Allure reporting integration
- Docker containerization
Created as part of QA Engineer assessment for QTeam Solutions.
This project is for assessment purposes.