Skip to content

Latest commit

 

History

History
73 lines (50 loc) · 3.57 KB

File metadata and controls

73 lines (50 loc) · 3.57 KB

Project Architecture

This document outlines the architecture of the Python BDD testing project.

Overview

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.

Core Technologies

  • 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

Directory Structure

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.)

BDD Framework

The BDD framework is built around the following components:

  • .feature files: These files are written in Gherkin syntax and describe application behavior in a series of scenarios. They are located in app/features/ directory.
  • Step Definitions: These are Python functions that implement the Gherkin steps. They are decorated with @given, @when, and @then and are located in app/features/steps/ directory.
  • Templates: Jinja2 templates (.j2) are used to generate .feature files 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 in app/test_data/.

Page Object Model (POM)

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) in app/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.

Data-Driven Testing

The framework supports data-driven testing where test scenarios can be run with multiple data sets:

  • Excel Data: Test data is read from .xlsx files and converted to Gherkin Examples tables.
  • YAML Data: Test data can be loaded from YAML files and used as Gherkin Backgrounds.

Configuration

  • Settings: Default settings are stored in app/settings/defaults.yaml.
  • Secrets: Sensitive configuration (credentials, API keys) are stored in app/secrets/.

Supporting Code

  • app/template.py: Jinja2 template processor that generates .feature files from templates and data.
  • app/lib/: Helper modules for common tasks (networking, YAML handling).

Execution

Tests can be executed using the nix run .#test command, which provides a fully reproducible environment.