A robust Python-based automation testing framework using Playwright with Page Object Model (POM) design pattern.
- Page Object Model (POM) - Maintainable and reusable code structure
- Comprehensive Logging - Detailed logs in both console and file
- HTML Reports - Beautiful test execution reports
- Allure Reports - Beautiful, interactive test execution reports
- CI/CD Ready - GitHub Actions and Jenkins support
- Configurable - Easy configuration management
- Cross-browser Testing - Chromium, Firefox, WebKit support
playwright-automation/
├── .github/
│ └── workflows/
│ └── playwright-tests.yml # GitHub Actions workflow
├── pages/
│ ├── __init__.py
│ ├── base_page.py # Base page with common methods
│ └── login_page.py # Login page object
├── tests/
│ ├── __init__.py
│ ├── conftest.py # Pytest fixtures and hooks
│ └── test_login.py # Login test cases
├── config/
│ ├── __init__.py
│ └── config.py # Configuration settings
├── utils/
│ ├── __init__.py
│ └── logger.py # Logging utility
├── logs/
│ └── automation.log # Test execution logs
├── reports/
│ └── report.html # HTML test reports
├── Jenkinsfile # Jenkins pipeline configuration
├── README.md # This file
├── requirements.txt # Python dependencies
└── pytest.ini # Pytest configuration
- Python 3.8 or higher
- pip (Python package manager)
- Git
- Clone the repository:
git clone <your-repo-url>
cd playwright-automation- Create virtual environment:
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt
playwright installpytest tests/test_login.pypytest tests/test_login.py::TestLogin::test_successful_login_with_valid_credentialspytest tests/test_login.py --html=reports/report.html --self-contained-html# Change HEADLESS = False in config/config.py
pytest tests/test_login.pypytest tests/test_login.py -v -spytest tests/test_login.py -m smoke1. pytest --alluredir=reports/allure-results
2. allure serve reports/allure-results| Test Case | Description | Expected Result |
|---|---|---|
| test_successful_login_with_valid_credentials | Login with valid username and password | PASS ✅ |
| test_login_with_invalid_username | Login with invalid username | PASS ✅ |
| test_login_with_invalid_password | Login with valid username but invalid password | PASS ✅ |
| test_login_with_empty_credentials | Login with empty credentials | FAIL ❌ (Intentional) |
Logs are generated in two formats:
- Console Output - Real-time logs during test execution
- File Logging - Detailed logs saved to
logs/automation.log
- DEBUG - Detailed information for debugging
- INFO - General information about test execution
- WARNING - Warning messages
- ERROR - Error messages
- CRITICAL - Critical issues
Edit config/config.py:
LOG_LEVEL = "INFO" # Change to DEBUG for more details
CONSOLE_LOG = True # Set to False to disable console logs
LOG_FILE = "logs/automation.log"Edit config/config.py to customize:
class Config:
BASE_URL = "https://the-internet.herokuapp.com/login"
VALID_USERNAME = "tomsmith"
VALID_PASSWORD = "SuperSecretPassword!"
TIMEOUT = 30000
HEADLESS = False # Set to True for CI/CD
LOG_LEVEL = "INFO"
CONSOLE_LOG = TrueThe framework includes a GitHub Actions workflow that:
- Runs on push and pull requests
- Executes tests on Ubuntu
- Generates HTML reports
- Archives test artifacts
Workflow file: .github/workflows/playwright-tests.yml
The framework includes a Jenkinsfile that:
- Runs tests in a Docker container
- Generates and archives HTML reports
- Publishes HTML reports in Jenkins UI
- Archives logs
Pipeline file: Jenkinsfile
To use in Jenkins:
- Create a new Pipeline job
- Point to your repository
- Jenkins will automatically detect the Jenkinsfile
- Create a new page object in
pages/directory:
from pages.base_page import BasePage
class NewPage(BasePage):
# Define locators
ELEMENT = "#element-id"
def interact_with_element(self):
self.page.click(self.ELEMENT)- Create test file in
tests/directory:
import pytest
from utils.logger import Logger
class TestNewFeature:
def test_something(self, browser_context):
logger = Logger.get_logger(self.__class__.__name__)
logger.info("Test started")
# Your test code here- Page Object Model - Keep page objects separate from test logic
- Logging - Log important actions and verifications
- Assertions - Use descriptive assertion messages
- Fixtures - Reuse fixtures for common setup/teardown
- Independent Tests - Each test should be independent
- Clear Naming - Use descriptive names for tests and methods
playwright installpip install -r requirements.txtchmod +x venv/bin/activate- Increase timeout in
config/config.py - Check network connectivity
- Verify test data
HTML reports are generated in the reports/ directory:
- Test execution summary
- Pass/Fail status
- Screenshots (if configured)
- Execution time
- Error details
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
For questions or support, please open an issue in the repository.
This project is licensed under the MIT License.
Happy Testing! 🎉