This document outlines the architecture of the Python BDD testing project.
The project is a testing framework that uses Behavior-Driven Development (BDD) to automate web browser testing. It is designed to be highly modular, separating test logic, test data, and page object models. This separation allows for easier maintenance and scalability of the test suite.
- Behave: BDD framework for Gherkin (.feature) files
- Robot Framework: Used as a wrapper around Selenium to simplify browser automation
- Selenium: Underlying browser interaction engine
- Jinja2: Templating engine for generating feature files
- PyYAML: Configuration and test data management
- Pandas: Excel file processing for test data
- Nix: For reproducible build environments and dependency management
The project is organized into the following key directories:
app/
├── features/ # Gherkin .feature files and step definitions
│ ├── steps/ # Python step implementations
│ └── templates/ # Jinja2 templates (.j2) for generating features
├── page_data/ # Page Object Model (POM) implementations
│ └── [website]/ # Website-specific page objects and locators
├── test_data/ # Test data files (Excel, YAML)
│ └── recipes/ # Reusable Gherkin snippets
├── lib/ # Helper libraries
├── settings/ # Default configuration
└── secrets/ # Sensitive data (credentials, etc.)
The BDD framework is built around the following components:
.featurefiles: These files are written in Gherkin syntax and describe application behavior in a series of scenarios. They are located inapp/features/directory.- Step Definitions: These are Python functions that implement the Gherkin steps. They are decorated with
@given,@when, and@thenand are located inapp/features/steps/directory. - Templates: Jinja2 templates (
.j2) are used to generate.featurefiles with different data sets. This enables data-driven testing from Excel or YAML files. - Data: Test data is stored in Excel (
.xlsx) or YAML (.yaml) files inapp/test_data/.
The project follows the Page Object Model pattern for website automation:
- Page Classes: For each page, there is a corresponding Python class (e.g.,
HomePage,ResultsPage) inapp/page_data/[website]/. - Page Locators: Web element locators (CSS selectors, XPaths) are stored in separate YAML files within
app/page_data/[website]/[page]/. - Separation of Concerns: Locators are separated from page logic, making it easier to maintain them when the UI changes.
The framework supports data-driven testing where test scenarios can be run with multiple data sets:
- Excel Data: Test data is read from
.xlsxfiles and converted to Gherkin Examples tables. - YAML Data: Test data can be loaded from YAML files and used as Gherkin Backgrounds.
- Settings: Default settings are stored in
app/settings/defaults.yaml. - Secrets: Sensitive configuration (credentials, API keys) are stored in
app/secrets/.
app/template.py: Jinja2 template processor that generates.featurefiles from templates and data.app/lib/: Helper modules for common tasks (networking, YAML handling).
Tests can be executed using the nix run .#test command, which provides a fully reproducible environment.