Skip to content

cesedebe/E-comm-pytest-automation

Repository files navigation

QA Automation Framework for E-Commerce Testing 🚀

Python Version PyTest WooCommerce Parallel Tests

✨ Highlights

  • 100+ automated tests across frontend, API, and database
  • Parallel execution using pytest-xdist
  • CI/CD ready: GitLab CI, GitHub Actions, Jenkins
  • HTML, JUnit, and Allure reporting with screenshots on failure

📋 Overview

A professional-grade test automation framework designed for E-Commerce applications built with WordPress and WooCommerce. It covers frontend (using Selenium), API, and database testing using Python and PyTest, and integrates with CI/CD systems like GitLab CI, GitHub Actions, and Jenkins. Developed to simulate real-world automation workflows, reporting, and environments.

E-Commerce Website Under Test: Demo Store

🎯 Key Features

  • Comprehensive Test Coverage: 100+ tests covering frontend, backend, and database layers
  • Advanced Reporting:
    • HTML reports with detailed test execution information
    • Allure reports with beautiful dashboards and analytics
    • Automatic screenshot capture on test failures
  • CI/CD Integration:
    • GitLab CI pipeline configuration
    • Jenkins pipeline setup
    • GitHub Actions workflow
  • Parallel Execution: Optimized test execution across multiple workers
  • End-to-End Testing: Comprehensive test coverage for both frontend and backend
  • API Testing: Robust API test suite for WooCommerce endpoints
  • Database Testing: Integration with MySQL for data validation
  • Cross-Browser Support: Test execution across multiple browsers
  • Docker Support: Containerized test execution environment

📸 Project Screenshots

Test Reports

HTML Report

HTML test report with detailed execution information

Allure Dashboard

Allure Report Dashboard showing test execution overview

Test Failure Screenshot Allure

Automatically captured screenshot on test failure (Allure)

Test Failure Screenshot HTML Report

Automatically captured screenshot on test failure (pytest-html)

🛠️ Technical Stack

  • Programming Language: Python 3.13+
  • Testing Framework: PyTest
  • Web Automation: Selenium WebDriver
  • API Testing: Requests library
  • Database: MySQL
  • Containerization: Docker
  • CI/CD: GitLab CI, Jenkins, GitHub Actions
  • Parallel Testing: pytest-xdist

🧱 Architecture Overview

The framework follows a modular architecture with a clear separation between test layers and utility logic. Tests are structured using the Page Object Model for frontend coverage, helper modules for API and database testing, and configuration files to support multiple environments.

The automation flow involves:

  • Selenium-based UI tests interacting with a live WooCommerce frontend
  • REST API tests targeting WooCommerce endpoints
  • MySQL integration to verify backend data consistency
  • CI/CD pipelines (Jenkins, GitLab CI, GitHub Actions) automatically triggering tests and publishing reports
  • Allure and HTML reporting for detailed visibility

Architecture Diagram
Overall architecture showing test layers, CI triggers, and reporting flow

🚀 Getting Started

Prerequisites

  • Python 3.13 or higher
  • Docker (optional, for containerized execution)
  • Access to a WordPress + WooCommerce site with StoreFront theme
  • MySQL database access

Setting Up Your Local Testing Environment

To get the most out of this framework, users can set up their own local WordPress + WooCommerce site for testing. This provides complete control over the test environment and allows for safe experimentation.

Written Tutorial

Follow the comprehensive written guide to set up a local testing environment: Setting Up WordPress & WooCommerce for Testing

Video Tutorial Series

Watch the step-by-step video series:

  1. Part 1: Installing WordPress
  2. Part 2: Configuring The Site
  3. Part 3: Verifying API and Frontend Checkout

These resources guide users through:

  • Setting up a local development environment
  • Installing and configuring WordPress
  • Setting up WooCommerce
  • Creating test products and categories
  • Setting up API keys for testing
  • Verifying the checkout process

Quick Start

  1. Clone the repository (choose one based on your preferred CI/CD platform):
# For GitHub
git clone https://github.com/cesedebe/E-comm-pytest-automation.git

# For GitLab
git clone git@gitlab.com:cesedebe/E-comm-pytest-automation.git

cd qa-bootcamp-framework

Note: The same codebase is maintained in both GitHub and GitLab to provide hands-on experience with different CI/CD platforms. Choose the repository that aligns with your learning goals:

  • GitHub repository for GitHub Actions
  • GitLab repository for GitLab CI
  • Either repository can be used with Jenkins CI
  1. Set up virtual environment and install dependencies:
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
  1. Configure environment variables (see Configuration section below)

  2. Run tests:

cd demostore_automation
python3 -m pytest tests

⚙️ Configuration

The framework uses environment variables for configuration. Create a variables_local.sh (Linux/Mac) or variables_local.bat (Windows) file with the following variables:

export BASE_URL=<your_website_url>
export BROWSER=<browser_name>  # chrome, firefox, headlesschrome,...
export RESULTS_DIR=$(pwd)/results
export DB_PORT=<your_database_port>
export DB_HOST=<your_database_host>
export DB_DATABASE=<your_database_name>
export DB_TABLE_PREFIX=<table_prefix>  # typically wp_ for WordPress
export WOO_KEY=<your_woocommerce_key>
export WOO_SECRET=<your_woocommerce_secret>
export DB_USER=<your_db_user>
export DB_PASSWORD=<your_db_password>

🔄 Parallel Test Execution

Overview

The framework uses pytest-xdist for parallel test execution, providing significant speed improvements for large test suites. Tests are distributed across multiple workers, with each worker running its own browser instance.

Configuration

Parallel execution is configured in pytest.ini with the following settings:

addopts = -n auto --dist=loadscope
  • -n auto: Automatically determines the optimal number of workers based on CPU cores
  • --dist=loadscope: Groups tests by module/class to maintain test isolation

Running Tests

Parallel Execution (Default)

# Run all tests in parallel
pytest tests/

# Run specific test directory in parallel
pytest tests/frontend/

# Run with specific number of workers
pytest -n 4 tests/

Sequential Execution

# Run tests sequentially
pytest -n 0 tests/

# Run specific test file sequentially
pytest -n 0 tests/frontend/test_login.py

# Run tests by marker
pytest -n 0 -m smoke tests/  # Run all tests marked with @pytest.mark.smoke
pytest -n 0 -m "not smoke" tests/  # Run all tests not marked with @pytest.mark.smoke

Test Distribution Strategy

  • Tests are grouped by module/class using --dist=loadscope
  • This ensures related tests run on the same worker
  • Each worker gets its own browser instance and profile
  • Browser profiles are stored in /tmp/ with worker-specific identifiers

Best Practices

  1. Test Isolation: Ensure tests are properly isolated and don't share state
  2. Resource Management: Monitor system resources when running in parallel
  3. Debugging: Use -n 0 for easier debugging of specific tests
  4. CI/CD: Parallel execution is ideal for CI/CD pipelines to reduce execution time

📄 Test Structure

This project separates test code and supporting logic into two main folders:

  • demostore_automation/: Contains all tests (frontend, backend, health checks)
  • src/: Contains reusable modules such as page objects, API utilities, data access, and custom Selenium extensions

This separation helps maintain clean architecture and enables easier reuse of logic across test suites.

demostore_automation/
├── tests/
│   ├── frontend/     # UI automation tests
│   ├── backend/      # API and database tests
│   └── test_healthcheck.py  # Health check tests
├── src/
│   ├── pages/        # Page object models
│   ├── api_helpers/  # API helper functions
│   ├── generic_helpers/  # Generic helper functions
│   ├── selenium_extended/  # Extended Selenium functionality
│   ├── configs/      # Configuration files
│   ├── dao/          # Data Access Objects
│   ├── utilities/    # Utility functions
│   └── data/         # Test data
├── scripts/          # Utility scripts
├── pytest.ini        # pytest configuration
└── conftest.py       # pytest fixtures and hooks

📊 Test Execution

  • Run all tests: python3 -m pytest tests
  • Run frontend tests: python3 -m pytest tests/frontend
  • Run backend tests: python3 -m pytest tests/backend
  • Run specific test: python3 -m pytest tests -m tcid33

📊 Test Reports

The framework supports three types of test reports, each with its own advantages:

1. HTML Reports (Simple and Quick)

HTML reports provide a straightforward way to view test results with basic information about test execution.

Generating HTML Reports

# Run tests with HTML report generation
cd demostore_automation
python3 -m pytest tests --html=reports/report.html

# View the report
open reports/report.html  # On Mac
# or
start reports/report.html  # On Windows

HTML reports include:

  • Test execution status (passed/failed)
  • Test duration
  • Error messages for failed tests
  • Basic test information
  • Screenshot of page if a test fails

2. JUnit XML Reports (CI/CD Integration)

JUnit XML reports are particularly useful for CI/CD integration and test result analysis in various tools.

Generating JUnit Reports

# Run tests with JUnit XML report generation
cd demostore_automation
python3 -m pytest tests --junitxml=reports/junit.xml

JUnit reports are used by:

  • Jenkins for test result visualization and trend analysis
  • GitLab CI for test result parsing and reporting
  • GitHub Actions for test result integration
  • Various test result visualization tools
  • Test result aggregation platforms

3. Allure Reports (Advanced and Beautiful)

Allure reports provide a more sophisticated and visually appealing way to analyze test results, with detailed information and analytics.

Generating and Viewing Allure Reports

The process involves three sequential steps:

  1. First, run tests and collect Allure results:
cd demostore_automation
python3 -m pytest tests --alluredir=./allure-results
  1. Then, generate the HTML report from the collected results:
allure generate ./allure-results -o ./allure-report --clean
  1. Finally, you can view the report in one of two ways:
    • Serve the report locally (temporary server):
    allure serve ./allure-results
    • Or open the generated HTML report directly:
    open ./allure-report/index.html  # On Mac
    # or
    start ./allure-report/index.html  # On Windows

Note: The allure serve command creates a temporary web server to view the report, while allure generate creates static HTML files that can be shared or hosted.

Allure Report Features

Allure Dashboard

Allure Report Dashboard showing test execution overview

Allure reports provide:

  • Test execution history
  • Detailed test case information
  • Step-by-step test execution
  • Screenshots and attachments
  • Test categorization and grouping
  • Historical trends and statistics

Choosing Between Report Types

  • Use HTML reports for quick, simple test result viewing
  • Use JUnit reports for CI/CD integration and test result analysis
  • Use Allure reports for detailed analysis, historical trends, and beautiful visualization

📈 CI/CD Integration

This framework integrates with:

  • GitLab CI via .gitlab-ci.yml
  • Jenkins using a Jenkinsfile located in the root directory
  • GitHub Actions using .github/workflows/main.yml

Each pipeline automatically:

  • Installs dependencies
  • Activates the Python virtual environment
  • Loads environment variables securely
  • Runs frontend and backend test suites
  • Publishes reports (HTML, JUnit, Allure)
  • Sends results to the Automation Dashboard (if configured)

You can view example pipelines in the screenshots section above.

📚 Learning Resources

📞 Contact

For questions or support, please open an issue in the repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy