Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Playwright Python E2E Test Automation

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.

🚀 Tech Stack

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.)

📁 Project Structure

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

⚙️ Setup

1. Clone the repository

git clone https://github.com/AbrarRagib/playwright-python-e2e.git
cd playwright-python-e2e

2. Create and activate a virtual environment

python -m venv venv
.\venv\Scripts\Activate.ps1        # Windows PowerShell
# source venv/bin/activate         # macOS / Linux

3. Install dependencies

pip install -r requirements.txt

4. Install Playwright browsers

playwright install

▶️ Running Tests

⚠️ Test files must be run with pytest, not python. Plain python only defines the test functions — pytest is what discovers them, launches the browser, and injects the page fixture.

Run all tests (headless, fast):

pytest

Run with a visible browser:

pytest --headed

Watch tests slowly (great for debugging / learning):

pytest -s --headed --slowmo 800

Run a single file or a single test:

pytest test_login_full.py
pytest test_login_full.py::test_logout -s --headed

🧪 Test Coverage

The 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

📌 Useful Notes

  • Time units: all Playwright waits are in milliseconds (--slowmo 800 = 0.8s, wait_for_timeout(3000) = 3s).
  • Auto-waiting: Playwright actions (goto, fill, click) and expect() assertions wait automatically until elements are ready and continue the instant they are — no manual sleep needed.
  • Test credentials are provided publicly by SauceDemo (standard_user / secret_sauce).

🗺️ Roadmap

  • Refactor to Page Object Model (POM)
  • Add cart & checkout test suites
  • Add HTML test reports
  • Run tests in CI (GitHub Actions)

📄 License

Free to use for learning purposes.

About

Playwright + Python E2E test suite with POM, pytest fixtures, cross-browser runs & CI/CD via GitHub Actions.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages