End-to-end (E2E) test automation framework built with Playwright and pytest, written in Python. Tests run against SauceDemo — a free demo e-commerce site made for practicing test automation.
| Tool | Purpose |
|---|---|
| Python 3.12 | Programming language |
| Playwright | Browser automation (Chromium, Firefox, WebKit) |
| pytest | Test framework & runner |
| pytest-playwright | Plugin that provides browser fixtures (page, etc.) |
playwright-python-e2e/
├── test_1.py # Setup smoke test (browser launch check)
├── test_logIn.py # Basic login tests (success, failure, locked user)
├── test_login_full.py # Full login suite — 18 corner cases + parametrized matrix
├── pytest.ini # Pytest configuration
├── requirements.txt # Python dependencies
├── .gitignore
└── README.md
1. Clone the repository
git clone https://github.com/AbrarRagib/playwright-python-e2e.git
cd playwright-python-e2e2. Create and activate a virtual environment
python -m venv venv
.\venv\Scripts\Activate.ps1 # Windows PowerShell
# source venv/bin/activate # macOS / Linux3. Install dependencies
pip install -r requirements.txt4. Install Playwright browsers
playwright install
⚠️ Test files must be run withpytest, notpython. Plainpythononly defines the test functions — pytest is what discovers them, launches the browser, and injects thepagefixture.
Run all tests (headless, fast):
pytestRun with a visible browser:
pytest --headedWatch tests slowly (great for debugging / learning):
pytest -s --headed --slowmo 800Run a single file or a single test:
pytest test_login_full.py
pytest test_login_full.py::test_logout -s --headedThe login suite (test_login_full.py) covers:
- ✅ Happy path — valid credentials land on the inventory page
- 🚫 Empty inputs — missing username / password / both
- 🚫 Invalid credentials — wrong username, wrong password, both wrong
- 🔒 Account state — locked-out user gets the correct specific error
- 🔠 Case sensitivity — uppercase username/password rejected
- ␣ Input hygiene — whitespace padding, 1000-character input
- 🛡️ Security probes — SQL injection payload, XSS payload, direct URL access without login, session invalidation after logout
- 🎛️ UX — error banner can be dismissed
- 📊 Parametrized matrix — 7 negative credential combinations in one test
- Time units: all Playwright waits are in milliseconds (
--slowmo 800= 0.8s,wait_for_timeout(3000)= 3s). - Auto-waiting: Playwright actions (
goto,fill,click) andexpect()assertions wait automatically until elements are ready and continue the instant they are — no manualsleepneeded. - Test credentials are provided publicly by SauceDemo (
standard_user/secret_sauce).
- Refactor to Page Object Model (POM)
- Add cart & checkout test suites
- Add HTML test reports
- Run tests in CI (GitHub Actions)
Free to use for learning purposes.