A powerful, scalable automation framework combining Playwright for browser automation, Behave for BDD testing, Allure for reporting, Page Object Model for maintainable test structure, and AI-powered selector healing for robust test automation.
# Clone and set up
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- β¨ Key Features
- ποΈ Architecture
- π§ AI Selector Healing
- βοΈ Setup Guide
- π§ͺ Running Tests
- π Reporting
- π·οΈ Tag Filtering
- βοΈ Code Organization
- π Investigate Tracing
- π Log Files
| Feature | Description | Benefits |
|---|---|---|
| π§ AI Selector Healing | AI-powered selector recovery using Ollama | Self-healing tests, reduced maintenance |
| ποΈ 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 |
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Feature Files β β Step Defs β β Page Objects β
β (Gherkin) βββββΆβ (Test Logic) βββββΆβ (Selectors) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Behave β β Playwright β β Allure β
β (BDD Engine) β β (Browser) β β (Reporting) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β AI Selector β β Ollama β β Selector β
β Healer βββββΆβ (AI Model) βββββΆβ Map Cache β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
The framework includes an intelligent AI-powered selector healing system that automatically recovers from selector failures using the Ollama AI model.
- Automatic Detection: When a selector fails (throws an exception), the system automatically triggers AI healing
- Context Capture: Captures current page screenshot and HTML content
- AI Analysis: Uses Ollama (
devstral:24bmodel) to analyze the page and suggest new selectors - Validation: Validates AI-suggested selectors before using them
- Learning: Maintains a
selector_map.jsonfile for future reference
- π§ Intelligent Recovery: AI analyzes page structure and suggests optimal selectors
- πΈ Visual Analysis: Uses screenshots for better element identification
- π― Confidence Scoring: AI provides confidence levels for suggested selectors
- π Historical Learning: Maintains selector mapping for reuse and learning
- π Multiple Selector Types: Supports XPath, CSS, and text-based selectors
- β‘ Automatic Integration: Seamlessly integrated into Page Object Model
# In base_page.py - Automatic AI healing
def fill_input(self, selector: str, value: str):
try:
self.page.locator(selector).wait_for(timeout=5000)
self.page.fill(selector, value)
except playwright.sync_api.TimeoutError:
# AI healing automatically triggered
locator = ai_selector_healing(context=self.context, text=selector)
locator.fill(value)- π Self-Healing Tests: Tests automatically recover from selector changes
- π Reduced Maintenance: Less manual selector updates required
- π― Higher Reliability: AI suggests robust, context-aware selectors
- π Continuous Learning: Improves over time with historical data
- β‘ Faster Development: Reduces debugging time for selector issues
- The AI method is ready, and requires the user to adjust base_page.py functions
- Use the @ai_healing tag to see AI in action
- Python 3.12+
- Git (for version control)
- Allure (for reporting)
- Ollama (for AI models)
# Create a 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
# Install Python packages
pip install -r requirements.txt
# Install Playwright browsers
playwright install
# 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
# Install Ollama
https://ollama.ai/
# Pull the required model
ollama pull devstral:24b
Set URL in Config.yaml:
base_url: https://httpbin.orgImportant: The base_url is required in config.yaml. The framework will raise an error if it's missing.
The AI selector healing system is automatically configured and ready to use. It will:
- Create
selector_map.jsonfor historical selector mapping - Generate
selector_log.jsonfor AI interaction logs - Capture screenshots in
reports/screenshots/ai-*.pngfor AI analysis - Use the
devstral:24bOllama model by default
# Run a quick test
python run_tests.py --tags @smoke --headlessNote: The AI selector healing will automatically activate when selectors fail. You can monitor AI interactions in the console output and check the generated logs.
python3 run_tests.py --help# 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
# Run with tracing
python run_tests.py --tracing
# Run with optimal worker count
python run_tests.py --parallel
# and so on# Parallel execution with a 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# Generate and serve a report
python run_tests.py --tags @smoke --serve-report
# Or manually serve the existing report
allure serve reports/allure-results- π 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
reports/
βββ allure-results/ # Allure report data
β βββ *.json # Test results
β βββ *.xml # Test metadata
βββ screenshots/ # Failure screenshots
β βββ screenshot_*.png # Automatic screenshots
β βββ ai-*.png # AI screenshots
βββ workers/ # Parallel execution logs
βββ worker_*.log # Worker-specific logs
- Keep selectors in page objects - Centralized element management
- Keep assertions in step definitions - Test logic separation
- Use Playwright's
expect()- Reliable assertions - Create reusable page methods - Reduce code duplication
Available tags in the framework:
@smoke- Quick validation tests@regression- Comprehensive test suite@api- API testing scenarios@performance- Performance testing
-
Keep step definitions focused
@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()
-
Use page objects for interactions
def click_login_button(self): self.click_element(self.LOGIN_BUTTON)
-
Use Playwright assertions
expect(context.page).to_contain_text("Welcome")
# 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.zipCheck log files for detailed error information:
reports/test.log- Detailed test execution logsreports/workers/- Parallel execution logsreports/traces/- Tracing reports
Monitor AI selector healing activities:
selector_map.json- Historical selector mappings and AI suggestionsselector_log.json- Detailed AI interaction logs with confidence scoresreports/screenshots/ai-*.png- Screenshots captured for AI analysis- Console output - Real-time AI healing notifications with emojis
Built with β€οΈ using Python, Playwright, Behave, Allure, and AI-powered selector healing