SauceDemo UI Tests with Selenium¶
A UI test suite for SauceDemo, a sample e-commerce website by SauceLabs for practicing test automation. It is built with Selenium WebDriver and pytest and covers the main e-commerce scenarios with 28+ tests, step-by-step logs and HTML reports.
What's Covered¶
- Login — 7 tests: valid/invalid credentials, locked user, logout, error handling
- Inventory — 7 tests: sorting, filtering, product selection
- Product — 2 tests: navigation, add to cart
- Cart — 3 tests: add/remove items, continue shopping
- Checkout — 4 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 — one class per page, reusable actions in a base page, locators kept separately in
locators/page_locators.py. - Fixture-based setup — pytest fixtures provide the Chrome WebDriver, page objects, a Faker data generator and automatic test logging.
- Base test class — every test class inherits from
BaseTest, which injects thepagesanddatafixtures. - Dual logging — detailed file logs in
logs/with expected vs actual values for assertions, plus logs embedded in the pytest-html report. - Browser configuration — Chrome with password popups and automation detection disabled, headless and UI modes, tuned for CI/CD and Docker.
Tech Stack¶
pytest— testing frameworkselenium— browser automationwebdriver-manager— automatic ChromeDriver managementfaker— test data generationpytest-html— HTML reports with logspython-dotenv— environment configurationuv— Python package managerruff— linter and formatter
Running It¶
Install dependencies, then run the tests headless or with an HTML report:
make install
make test
make test-html