A modern test automation framework using Playwright and Python for website testing, featuring Behavior Driven Development (BDD).
- Behavior Driven Development with pytest-bdd
- Page Object Model pattern for maintainable test structure
- Strong typing with Python type hints
- Modular test organization (e2e, components, features)
- Configuration management via .env
- Utility functions for common test operations
- Cross-browser testing support
- HTML reporting
- Local test server using Flask
/playwright-python-website
├── config/ # Test configurations
├── page_objects/ # Page object models
├── tests/ # Test files
│ ├── e2e/ # End-to-end tests
│ ├── components/ # Component tests
│ └── features/ # BDD feature files and steps
│ ├── steps/ # Step definitions
│ └── conftest.py # BDD fixtures
├── utils/ # Helper utilities
└── reports/ # Test execution reports
- Python 3.8+
- pip (Python package installer)
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Create a .env
file in the root directory with the following settings:
BROWSER=chromium
HEADLESS=false
SLOW_MO=0
BASE_URL=http://localhost:5000
VIEWPORT_WIDTH=1280
VIEWPORT_HEIGHT=720
TIMEOUT=30000
- Start the local test server:
python app.py
- Run all tests:
pytest
- Run specific test file:
pytest tests/e2e/test_example.py -v
- Run BDD feature tests:
pytest tests/features/steps/ -v
- Generate HTML report:
pytest --html=reports/report.html
- Feature Files: Gherkin syntax for BDD scenarios
- Step Definitions: Python implementations of BDD steps
- Page Objects: Reusable functions for page interactions
- E2E Tests: End-to-end test scenarios
- Component Tests: Individual component testing
- Utilities: Helper functions for common operations
-
BDD Implementation
- Write clear, descriptive feature files
- Use reusable step definitions
- Implement strong fixtures
- Follow Given-When-Then pattern
-
Code Style
- Use functional programming patterns
- Follow snake_case naming convention
- Include proper type hints (Dict, Any, Callable)
- Write modular, reusable code
-
Error Handling
- Implement strong error handling
- Use proper timeouts and waits
- Handle network requests properly
- Include descriptive error messages
- Handle CAPTCHA and rate limiting gracefully
-
Documentation
- Add docstrings to all functions
- Document test scenarios clearly
- Keep README up to date
- Generate and maintain test reports
- Document lessons learned
- Follow the established code style
- Add proper documentation
- Write tests for new features
- Update README as needed
- Document lessons learned
- Python 3.8+
- Playwright 1.42.0
- pytest 7.4.4
- pytest-playwright 0.4.3
- pytest-bdd 7.1.2
- Flask 3.0.2
- pytest-html 4.1.1
- python-dotenv 1.0.0
- parse 1.20.1
- parse-type 0.6.2
- LessonLearned.md - Detailed documentation of implementation insights and best practices
- pytest-bdd Documentation - Official pytest-bdd documentation
- Playwright Documentation - Official Playwright Python documentation