A comprehensive Behavior-Driven Development (BDD) test automation framework using Selenium WebDriver for UI testing and Python Requests for API testing, enhanced with BehaveX for parallel execution and advanced reporting.
- π Dual Testing Support: UI testing with Selenium + API testing with Requests
 - β‘ Parallel Execution: Run tests in parallel using BehaveX
 - π Enhanced Reporting: Allure, JUnit, HTML, and custom reports
 - ποΈ Page Object Pattern: Reusable page objects with JSON-based element management
 - π§ Configuration Management: Environment-specific configurations
 - π Cross-Browser Testing: Chrome, Firefox, Edge support
 - π» Headless Execution: Run tests without browser UI
 - π Auto-Retry: Automatic retry for failed scenarios
 - πΈ Evidence Collection: Screenshots, logs, and execution traces
 - π Test Muting: Skip specific tests dynamically
 - π Performance Metrics: Response time tracking and analysis
 
bdd-framework/
βββ π config/                          # Environment configurations
β   βββ dev_config.json
β   βββ stg_config.json
β   βββ prod_config.json
βββ π elements/                        # Element locators (JSON)
β   βββ facebook_login_page.json
β   βββ *.json
βββ π features/                        # BDD feature files
β   βββ π steps/                       # Step definitions
β   β   βββ facebook_login_signup_steps.py
β   β   βββ Todos_API_Testing_Steps.py
β   βββ facebook_login_signup.feature
β   βββ Todos_API_Testing.feature
βββ π pages/                          # Page Object classes
β   βββ base_page.py
β   βββ facebook_login_signup_page.py
βββ π reports/                        # Test reports and artifacts
β   βββ π allure-results/
β   βββ π junit/
β   βββ π screenshots/
β   βββ π logs/
βββ π testdata/                       # Test data files
β   βββ π facebook/
β       βββ facebook_login_data.json
β       βββ facebook_createuser_data.json
βββ π utils/                          # Utility classes
β   βββ config_manager.py
β   βββ logger.py
β   βββ selenium_client.py
β   βββ api_client.py
β   βββ allure_helper.py
β   βββ enhanced_reporter.py
β   βββ parallel_runner.py
β   βββ test_retry_handler.py
β   βββ page_factory.py
β   βββ file_reader.py
βββ π run_tests.py                    # Main test runner
βββ π environment.py                  # Behave environment setup
βββ π requirements.txt                # Dependencies
βββ π README.md                       # This file
Before you begin, ensure you have:
- β Python 3.8 or higher (Download Python)
 - β pip (Python package manager)
 - β Git (Download Git)
 
git clone https://github.com/DipankarDandapat/Python_Selenium_BDD_Framework.git
cd Python_Selenium_BDD_Framework# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate# Install all required Python packages
pip install -r requirements.txt# Check installation
python run_tests.py --helppython run_tests.py# Run only UI tests
python run_tests.py --type ui
# Run only API tests (no browser launched)
python run_tests.py --type api
# Run smoke tests
python run_tests.py --type smoke
# Run regression tests
python run_tests.py --type regression| Command | Description | 
|---|---|
python run_tests.py | 
Run all tests (UI + API) | 
python run_tests.py --type ui | 
Run UI tests only | 
python run_tests.py --type api | 
Run API tests only | 
python run_tests.py --type smoke | 
Run smoke tests | 
python run_tests.py --type regression | 
Run regression tests | 
| Command | Description | 
|---|---|
python run_tests.py --env dev | 
Run in development environment | 
python run_tests.py --env stg | 
Run in staging environment | 
python run_tests.py --env prod | 
Run in production environment | 
| Command | Description | 
|---|---|
python run_tests.py --browser chrome | 
Use Chrome browser (default) | 
python run_tests.py --browser firefox | 
Use Firefox browser | 
python run_tests.py --browser edge | 
Use Edge browser | 
python run_tests.py --headless | 
Run browser in headless mode | 
python run_tests.py --headed | 
Run browser in headed mode | 
| Command | Description | 
|---|---|
python run_tests.py --parallel 4 | 
Run with 4 parallel processes | 
python run_tests.py --processes 8 | 
Run with 8 parallel processes | 
python run_tests.py --type ui --parallel 4 | 
UI tests with 4 parallel processes | 
python run_tests.py --type api --parallel 6 | 
API tests with 6 parallel processes | 
| Command | Description | 
|---|---|
python run_tests.py --tags "@smoke" | 
Run tests with @smoke tag | 
python run_tests.py --tags "@regression" | 
Run tests with @regression tag | 
python run_tests.py --tags "@ui,@smoke" | 
Run UI smoke tests | 
python run_tests.py --tags "@api,@regression" | 
Run API regression tests | 
python run_tests.py --tags "~@wip" | 
Skip work-in-progress tests | 
| Command | Description | 
|---|---|
python run_tests.py --allure | 
Generate Allure report | 
python run_tests.py --junit | 
Generate JUnit reports | 
python run_tests.py --allure --junit | 
Generate both reports | 
python run_tests.py --verbose | 
Verbose output | 
| Command | Description | 
|---|---|
python run_tests.py --dry-run | 
Dry run without executing tests | 
python run_tests.py --stop | 
Stop after first failure | 
python run_tests.py --no-capture | 
Don't capture stdout/stderr | 
python run_tests.py --tags-help | 
Show tags help | 
| Command | Description | 
|---|---|
python run_tests.py --type api --env stg --parallel 4 --allure | 
API tests on staging with parallel execution and Allure | 
python run_tests.py --type ui --browser firefox --headless --tags "@smoke" | 
UI smoke tests on Firefox headless | 
python run_tests.py --type regression --parallel 8 --junit --stop | 
Regression tests with parallel execution, JUnit reports, stop on failure | 
Create environment-specific JSON files in config/ directory:
config/dev_config.json
{
  "UI_BASE_URL": "https://www.facebook.com",
  "API_BASE_URL": "https://dipankardandapat.xyz",
  "BROWSER": "chrome",
  "HEADLESS": false,
  "IMPLICIT_WAIT": 10,
  "PAGE_LOAD_TIMEOUT": 30,
  "API_TIMEOUT": 30,
  "SCREENSHOT_ON_FAILURE": true,
  "LOG_LEVEL": "INFO",
  "API_KEY": "your-api-key-here",
  "PARALLEL_WORKERS": 4
}Store element locators in JSON files in elements/ directory:
elements/facebook_login_page.json
{
  "email": {
    "type": "css",
    "value": "#email"
  },
  "password": {
    "type": "id", 
    "value": "pass"
  },
  "loginButton": {
    "type": "xpath",
    "value": "//button[@name='login']"
  }
}css- CSS Selectorxpath- XPathid- Element IDname- Name attributeclass- Class nametag- Tag namelink- Link textpartial_link- Partial link text
features/facebook_login_signup.feature
@ui
Feature: Facebook Login Functionality
  As a Facebook user
  I want to log in to my account
  So that I can access my feed and interact with friends
  @smoke
  Scenario: Successful Login with Valid Credentials
    Given I am on the Facebook login page
    When I enter valid username and password
    And I click the login button
    Then I should be logged in successfully
  @regression
  Scenario: Unsuccessful Login with Invalid Password
    Given I am on the Facebook login page
    When I enter valid username and invalid password
    And I click the login button
    Then I should see an error message indicating invalid credentialsfeatures/Todos_API_Testing.feature
@api
Feature: Todos API Testing
  As a QA engineer
  I want to test the Todos REST API thoroughly
  So that I can ensure its functionality and data integrity
  @smoke @todos
  Scenario: Get all todos from API
    Given the API client is configured for the Todos API
    When I send GET request to "api/v1/todos"
    Then the response status code should be 200
    And the response should contain todos data structure
  @regression
  Scenario: Create a new todo via API
    Given I have valid todo data
    When I send POST request to "api/v1/todos" with the todo data
    Then the response status code should be 201
    And the response should contain the created todo detailsUI Steps (features/steps/facebook_login_signup_steps.py)
from behave import *
from features.pages.facebook_login_signup_page import FacebookLoginSignupPage
from utils.page_factory import get_page_object
@given("I am on the Facebook login page")
def step_impl(context):
    login_page = get_page_object(context, FacebookLoginSignupPage)
    login_page.navigate_to_facebook()
    login_page.verify_page_title("Facebook β log in or sign up")API Steps (features/steps/Todos_API_Testing_Steps.py)
from behave import given, when, then
@given('the API client is configured for the Todos API')
def step_impl(context):
    assert context.api_client is not None, "API client was not initialized"
@when('I send GET request to "{endpoint}"')
def step_impl(context, endpoint):
    context.response = context.api_client.get(endpoint)# Generate and view Allure report
python run_tests.py --allure
allure serve reports/allure-results
# Generate static Allure report
allure generate reports/allure-results -o reports/allure-report --clean
# Open generated report
allure open reports/allure-reportJUnit reports are automatically generated in reports/junit/ directory when using --junit flag.
Custom HTML reports with charts and metrics are generated in reports/ directory.
Sample HTML report showing test summary, charts, and detailed results
# Scenario-level parallelization (default)
python run_tests.py --parallel 4 --parallel-scheme scenario
# Feature-level parallelization  
python run_tests.py --parallel 2 --parallel-scheme featureConfigure automatic retry in behave.ini:
[behavex]
retry=2
retry_delay=1# Set environment variables
export TEST_ENV=stg
export BROWSER=firefox
export HEADLESS=true
# Run tests with environment variables
python run_tests.py# Run specific test groups
python run_tests.py --tags "@group1,@group2"
# Exclude specific groups
python run_tests.py --tags "~@exclude_group"Browser not starting?
- Check browser drivers are installed
 - Verify browser version compatibility
 - Ensure webdriver-manager can download drivers
 
API tests failing?
- Check network connectivity
 - Verify API endpoints and authentication
 - Check API response formats
 
Parallel execution issues?
- Ensure tests are independent
 - Check system resources (CPU, memory)
 - Verify no shared state between tests
 
Element not found?
- Check element locators in JSON files
 - Verify page loading timeouts
 - Check for iframes or dynamic content
 
# Run with debug logging
python run_tests.py --verbose --no-capture
# Run single scenario for debugging
python run_tests.py --tags "@debug" --no-capture- Logs: 
logs/directory - Screenshots: 
reports/screenshots/directory (on failure) - Allure results: 
reports/allure-results/ - JUnit reports: 
reports/junit/ 
- Use consistent tagging strategy
 - Group related scenarios in features
 - Separate UI and API tests with tags
 
- Keep locators in JSON files
 - Implement reusable page methods
 - Use page factory for lazy initialization
 
- Use environment-specific configs
 - Store sensitive data in environment variables
 - Version control configuration templates
 
- Attach screenshots on failures
 - Include API request/response details
 - Use descriptive scenario names
 
- Design tests to be independent
 - Avoid shared state between tests
 - Use appropriate parallel scheme
 
- Use headless mode for CI/CD pipelines
 - Implement smart waits instead of fixed sleeps
 - Use parallel execution for large test suites
 - Optimize test data setup and teardown
 - Use API calls for test data preparation when possible
 
name: Test Execution
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Run tests
        run: python run_tests.py --type all --headless --parallel 4 --allure
      - name: Generate Allure report
        run: allure generate reports/allure-results -o reports/allure-report --clean
      - name: Upload Allure report
        uses: actions/upload-artifact@v3
        with:
          name: allure-report
          path: reports/allure-reportThis framework is provided for educational and testing purposes. Please ensure compliance with the terms of service for any applications under test.
