A modular test automation framework using Playwright with Python and the Page Object Model (POM) design pattern.
test automation/
├── config/
│ └── config.py # Configuration settings (URLs, credentials, timeouts)
├── pages/
│ ├── base_page.py # Base page with common methods
│ └── login_page.py # Login page object
├── tests/
│ ├── test_login.py # Login test cases
│ └── test_login_extended.py # Additional login tests
├── conftest.py # Pytest fixtures and hooks
├── requirements.txt # Project dependencies
└── README.md # This file
# Install Python packages
pip install -r requirements.txt
# Install Playwright browsers
playwright installEdit config/config.py to set:
BASE_URL: Your website URLVALID_USERNAMEandVALID_PASSWORD: Valid credentials (if testing successful login)- Browser settings (headless mode, timeouts, etc.)
Edit pages/login_page.py to match your website's actual element locators:
- Inspect your login page elements
- Update the locator strings (CSS selectors, XPath, etc.)
pytestpytest tests/test_login.pypytest tests/test_login.py::TestLogin::test_login_with_wrong_usernamepytest --html=report.html --self-contained-htmlUpdate HEADLESS = False in config/config.py
pytest -m security # Run only security tests
pytest -m ui # Run only UI testspytest -n auto # Use all available CPU cores
pytest -n 4 # Use 4 workersCreate a new file in pages/ directory:
from pages.base_page import BasePage
from playwright.sync_api import Page
class DashboardPage(BasePage):
# Define locators
WELCOME_MESSAGE = "h1.welcome"
def __init__(self, page: Page):
super().__init__(page)
def get_welcome_message(self) -> str:
return self.get_text(self.WELCOME_MESSAGE)Create a new file in tests/ directory:
import pytest
from pages.dashboard_page import DashboardPage
from config.config import Config
class TestDashboard:
def test_dashboard_loads(self, page):
dashboard = DashboardPage(page)
dashboard.navigate_to(f"{Config.BASE_URL}/dashboard")
assert "Welcome" in dashboard.get_welcome_message()- Page Object Model: Keep page elements and methods in page objects
- DRY Principle: Use base page for common methods
- Fixtures: Use pytest fixtures for setup/teardown
- Assertions: Use clear, descriptive assertions
- Markers: Use pytest markers to organize tests (@pytest.mark.smoke, @pytest.mark.regression)
- Screenshots: Automatic screenshots on failure (configured in conftest.py)
Run tests in Docker containers with Allure reporting:
# Build image
docker build -t playwright-tests .
# Run tests
docker run --rm -v ${PWD}/allure-results:/app/allure-results playwright-tests
# View report
allure serve allure-resultsSee DOCKER.md for complete Docker instructions.
Tests automatically run on every push and pull request:
- Automated test execution on Ubuntu
- Allure reports published to GitHub Pages
- Screenshots uploaded as artifacts on failure
View live reports at: https://<your-username>.github.io/<repo-name>/
To enable GitHub Pages:
- Go to repository Settings → Pages
- Set Source to "Deploy from a branch"
- Select
gh-pagesbranch - Save and wait for the first workflow run
Current test scenarios:
- ✅ Login with wrong username
- ✅ Login with wrong password
- ✅ Login with empty username
- ✅ Login with empty password
- ✅ Login with both fields empty
- ✅ SQL injection prevention
- ✅ XSS prevention
- ✅ UI element visibility
Available in config/config.py:
- Browser type (chromium, firefox, webkit)
- Headless mode
- Timeouts
- Screenshot settings
- Video recording