https://github.com/prashant1507/playwright-behave-allure-framework
Python BDD test framework with Playwright, Behave, and Allure
https://github.com/prashant1507/playwright-behave-allure-framework
allure-reports bdd behave parallel-testing playwright python3
Last synced: 3 months ago
JSON representation
Python BDD test framework with Playwright, Behave, and Allure
- Host: GitHub
- URL: https://github.com/prashant1507/playwright-behave-allure-framework
- Owner: prashant1507
- Created: 2025-07-13T07:23:27.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-07-13T08:17:26.000Z (3 months ago)
- Last Synced: 2025-07-13T09:24:51.424Z (3 months ago)
- Topics: allure-reports, bdd, behave, parallel-testing, playwright, python3
- Language: Python
- Homepage: https://github.com/prashant1507/playwright-behave-allure-framework
- Size: 35.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Python Automation Framework with Playwright + Behave + Allure
[](https://python.org)
[](https://playwright.dev)
[](https://behave.readthedocs.io)
[](https://docs.qameta.io/allure/)A powerful, scalable automation framework combining **Playwright** for browser automation, **Behave** for BDD testing, *
*Allure** for reporting, and **Page Object Model** for maintainable test structure.## π Quick Start
```bash
# Clone and setup
git clone https://github.com/prashant1507/playwright-behave-allure-framework.git
cd playwright-behave-allure-framework/# Install dependencies
pip install -r requirements.txt
playwright install# Install node for checking tracing
brew install node# Run your first test
python run_tests.py --tags @smoke
```---
## π Table of Contents
- [β¨ Key Features](#-key-features)
- [ποΈ Architecture](#οΈ-architecture)
- [βοΈ Setup Guide](#οΈ-setup-guide)
- [π§ͺ Running Tests](#-running-tests)
- [π Reporting](#-reporting)
- [π·οΈ Tag Filtering](#tag-filtering)
- [οΏ½οΏ½ Code Organization](#code-organization)
- [π Investigate Tracing](#investigate-tracing)
- [π Log Files](#log-files)---
## β¨ Key Features
| Feature | Description | Benefits |
|-------------------------------|---------------------------------------------------------|-------------------------------------------------|
| ποΈ **Page Object Model** | Centralized element selectors and reusable page methods | Maintainable, scalable test structure |
| π **Parallel Execution** | Multi-worker test execution feature-by-feature | Faster test execution, efficient resource usage |
| π·οΈ **Smart Tag Filtering** | Filter tests by tags (`@smoke`, `@regression`, `@api`) | Run only relevant tests, reduce execution time |
| π **Enhanced Reporting** | Allure integration with automatic screenshots | Detailed HTML reports with failure analysis |
| βοΈ **Flexible Configuration** | YAML config + environment variables + command-line args | Easy configuration management |
| π **Multi-Browser Support** | Chromium, Firefox, WebKit support | Cross-browser testing capabilities |
| π― **Clean Output** | Filtered console output with organized reporting | Reduced noise, better debugging |---
## ποΈ Architecture
```
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Feature Files β β Step Defs β β Page Objects β
β (Gherkin) βββββΆβ (Test Logic) βββββΆβ (Selectors) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Behave β β Playwright β β Allure β
β (BDD Engine) β β (Browser) β β (Reporting) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
```---
## βοΈ Setup Guide
### 1. Prerequisites
- **Python 3.12+**
- **Git** (for version control)
- **Allure** (for reporting)### 2. Environment Setup
```bash
# Create virtual environment
python -m venv venv# Activate virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate# Upgrade pip
pip install --upgrade pip
```### 3. Install Dependencies
```bash
# Install Python packages
pip install -r requirements.txt# Install Playwright browsers
playwright install
```### 4. Install Allure (Optional)
```bash
# macOS (using Homebrew)
brew install allure# Windows (using Scoop)
scoop install allure# Linux
sudo apt-add-repository ppa:qameta/allure
sudo apt-get update
sudo apt-get install allure
```### 5. Configuration
#### Set URL in `config.yaml`:
```yaml
base_url: https://httpbin.org
```**Important:** The `base_url` is **required** in `config.yaml`. The framework will raise an error if it's missing.
### 6. Verify Installation
```bash
# Run a quick test
python run_tests.py --tags @smoke --headless
```---
## π§ͺ Running Tests
### Basic Test Execution
```bash
# Run all tests
python run_tests.py# Run specific feature files
python run_tests.py features/login.feature features/forms.feature# Run tagged tests
python run_tests.py --tags @smoke
python run_tests.py --tags @regression# Run with tracing
python run_tests.py --tracing
```### Parallel Execution
```bash
# Run with optimal worker count
python run_tests.py --parallel# Run with custom workers
python run_tests.py --parallel --workers 4# Run tagged tests in parallel
python run_tests.py --parallel --tags @smoke @regression
```### Browser Options
```bash
# Different browsers
python run_tests.py --browser chromium
python run_tests.py --browser firefox
python run_tests.py --browser webkit# Headless mode
python run_tests.py --headless
python run_tests.py --browser firefox --headless
```### Advanced Combinations
```bash
# Parallel execution with specific browser and headless mode
python run_tests.py --parallel --browser firefox --headless --workers 4# Run specific tags with custom configuration
python run_tests.py --tags @smoke @api --browser webkit --headless# Run with auto-serve report
python run_tests.py --tags @smoke --serve-report
```---
## π Reporting
### Allure Reports
```bash
# Generate and serve report
python run_tests.py --tags @smoke --serve-report# Or manually serve existing report
allure serve reports/allure-results
```### Report Features
- **π HTML Reports** - Detailed test results with trends
- **πΈ Screenshots** - Automatic capture on failures
- **π Failing Scenarios** - Clear summary of failed tests
- **π Trends** - Historical test execution data
- **π Detailed Analysis** - Step-by-step failure analysis### Report Structure
```
reports/
βββ allure-results/ # Allure report data
β βββ *.json # Test results
β βββ *.xml # Test metadata
βββ screenshots/ # Failure screenshots
β βββ screenshot_*.png # Automatic screenshots
βββ workers/ # Parallel execution logs
βββ worker_*.log # Worker-specific logs
```### Best Practices
1. **Keep selectors in page objects** - Centralized element management
2. **Keep assertions in step definitions** - Test logic separation
3. **Use Playwright's `expect()`** - Reliable assertions
4. **Create reusable page methods** - Reduce code duplication---
## Tag FilteringAvailable tags in the framework:
- `@smoke` - Quick validation tests
- `@regression` - Comprehensive test suite
- `@api` - API testing scenarios
- `@performance` - Performance testing```bash
# Single tag
python run_tests.py --tags @smoke# Multiple tags (OR logic)
python run_tests.py --tags @smoke @regression# Parallel with tags
python run_tests.py --parallel --tags @api
```---
### Code Organization
1. **Keep step definitions focused**
```python
@when("the user clicks the login button")
def step_click_login(context):
login_page = context.page_factory.get_login_page(context.page)
login_page.click_login_button()
```2. **Use page objects for interactions**
```python
def click_login_button(self):
self.click_element(self.LOGIN_BUTTON)
```3. **Use Playwright assertions**
```python
expect(context.page).to_contain_text("Welcome")
```---
### Investigate Tracing
```bash
# Install Playwright trace viewer
npx playwright show-trace reports/traces/FILE_NAME.zip# Or use the web interface
npx playwright show-trace --host 0.0.0.0 --port 8080 reports/traces/FILE_NAME.zip
```
---### Log Files
Check log files for detailed error information:
- `reports/test.log` - Detailed test execution logs
- `reports/workers/` - Parallel execution logs
- `reports/traces/` - Tracing reports---
*Built with β€οΈ using Python, Playwright, Behave, and Allure*