Skip to content

Robust QA automation suite designed to streamline testing of e-commerce platforms, ensuring reliability, scalability, and performance.

License

Notifications You must be signed in to change notification settings

egemenguney/ecommerce-test-suite

Repository files navigation

E-commerce Test Suite

CI/CD Python Selenium Pytest License

A comprehensive automated testing framework for e-commerce applications using Python, Selenium, and Pytest. This project demonstrates QA Automation skills and Python-Selenium expertise.

πŸ“‹ Project Overview

This test suite implements the Page Object Model (POM) pattern to test various e-commerce functionalities including:

  • User authentication (Login)
  • Product search
  • Shopping cart operations
  • Checkout process

πŸ› οΈ Technologies and Tools

  • Python 3.8+ - Programming language
  • Selenium 4.15.2 - Web automation framework
  • Pytest 7.4.3 - Test framework and runner
  • Pytest-HTML - HTML test reports
  • Pytest-Xdist - Parallel test execution
  • WebDriver Manager - Automatic driver management
  • Python-dotenv - Environment variable management
  • Allure Pytest - Advanced test reporting

πŸ“ Project Structure

ecommerce-test-suite/
β”œβ”€β”€ tests/                  # Test cases
β”‚   β”œβ”€β”€ test_login.py      # Login functionality tests
β”‚   β”œβ”€β”€ test_search.py     # Search functionality tests
β”‚   β”œβ”€β”€ test_cart.py       # Shopping cart tests
β”‚   └── test_checkout.py   # Checkout process tests
β”œβ”€β”€ pages/                  # Page Object Model classes
β”‚   β”œβ”€β”€ login_page.py      # Login page interactions
β”‚   β”œβ”€β”€ search_page.py     # Search page interactions
β”‚   β”œβ”€β”€ cart_page.py       # Cart page interactions
β”‚   └── checkout_page.py   # Checkout page interactions
β”œβ”€β”€ utils/                  # Utility functions
β”‚   β”œβ”€β”€ driver_setup.py    # WebDriver initialization
β”‚   └── config.py          # Configuration and test data
β”œβ”€β”€ demo-site/             # Demo e-commerce website (for testing)
β”‚   β”œβ”€β”€ index.html         # Homepage
β”‚   β”œβ”€β”€ login.html         # Login page
β”‚   β”œβ”€β”€ products.html      # Product listing
β”‚   β”œβ”€β”€ cart.html          # Shopping cart
β”‚   β”œβ”€β”€ checkout.html      # Checkout page
β”‚   └── ...                # Other pages and assets
β”œβ”€β”€ conftest.py            # Pytest fixtures and configuration
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ .env.example          # Environment variables template
β”œβ”€β”€ .gitignore            # Git ignore rules
└── README.md             # Project documentation

πŸš€ Getting Started

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • A web browser (Chrome, Firefox, or Edge)
  • Git (optional, for version control)

Installation

  1. Clone or download the project

    git clone <repository-url>
    cd ecommerce-test-suite
  2. Create a virtual environment (recommended)

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Start the demo e-commerce site

    # Navigate to demo-site folder
    cd demo-site
    
    # Start local server (choose one):
    # Option 1: Python HTTP Server
    python -m http.server 8000
    
    # Option 2: Use provided script
    # Windows:
    start-server.bat
    # Linux/Mac:
    chmod +x start-server.sh
    ./start-server.sh

    The demo site will be available at: http://localhost:8000

  5. Configure environment variables (optional)

    # Copy the example file
    cp .env.example .env
    
    # Edit .env file if you want to change default settings
    # Default settings work with the demo site

βš™οΈ Configuration

Demo Site Credentials

The included demo site uses these credentials:

Environment Variables

Edit the .env file to configure:

  • BASE_URL: The e-commerce site URL to test (default: http://localhost:8000)
  • TEST_USERNAME: Test account email (default: [email protected])
  • TEST_PASSWORD: Test account password (default: test123)
  • BROWSER: Browser to use (chrome, firefox, edge)
  • HEADLESS: Run tests in headless mode (True/False)
  • IMPLICIT_WAIT: Implicit wait time in seconds
  • EXPLICIT_WAIT: Explicit wait time in seconds

πŸ§ͺ Running Tests

Run all tests

pytest

Run specific test file

pytest tests/test_login.py

Run specific test class

pytest tests/test_login.py::TestLogin

Run specific test method

pytest tests/test_login.py::TestLogin::test_valid_login

Run tests with markers

# Run only smoke tests
pytest -m smoke

# Run only regression tests
pytest -m regression

# Run login-related tests
pytest -m login

Run tests in parallel

pytest -n auto

Generate HTML report

pytest --html=report.html --self-contained-html

Generate Allure report

# Run tests with Allure
pytest --alluredir=allure-results

# Generate and open report
allure serve allure-results

πŸ“ Test Cases

Login Tests (test_login.py)

  • βœ… Valid login with correct credentials
  • βœ… Invalid email login attempt
  • βœ… Invalid password login attempt
  • βœ… Empty credentials validation
  • βœ… Special characters handling

Search Tests (test_search.py)

  • βœ… Search valid product
  • βœ… Search invalid/non-existent product
  • βœ… Search with special characters
  • βœ… Empty search handling
  • βœ… Case-insensitive search
  • βœ… Search and select product

Cart Tests (test_cart.py)

  • βœ… Add product to cart
  • βœ… Remove product from cart
  • βœ… Update cart quantity
  • βœ… Empty cart verification
  • βœ… Cart total calculation

Checkout Tests (test_checkout.py)

  • βœ… Complete checkout with valid details
  • βœ… Checkout without accepting terms
  • βœ… Checkout with empty cart
  • βœ… Billing details validation

🎯 Page Object Model (POM)

This project follows the Page Object Model pattern:

  • Pages: Each page has its own class with locators and methods
  • Tests: Test files contain test cases that use page objects
  • Utils: Common utilities like driver setup and configuration

Example Usage

from pages.login_page import LoginPage

# Initialize page object
login_page = LoginPage(driver)

# Use page methods
login_page.navigate_to_login()
login_page.login("[email protected]", "password123")
assert login_page.is_login_successful()

πŸ“Š Test Reports

HTML Report

After running tests, open report.html in a browser to view detailed test results.

Allure Report

For more advanced reporting with Allure:

  1. Run tests: pytest --alluredir=allure-results
  2. Generate report: allure serve allure-results

Screenshots

Failed tests automatically capture screenshots in the screenshots/ directory.

πŸ”§ Troubleshooting

WebDriver Issues

  • Ensure you have the latest browser version installed
  • WebDriver Manager will automatically download the correct driver
  • If issues persist, manually download drivers from browser vendors

Import Errors

  • Ensure virtual environment is activated
  • Verify all dependencies are installed: pip install -r requirements.txt
  • Check that you're running tests from the project root directory

Locator Issues

  • Update locators in page objects if the website structure changes
  • Use browser DevTools to inspect elements and find correct selectors

πŸ“š Learning Resources

This project is designed as a learning resource. Key concepts demonstrated:

  • Page Object Model: Separation of page logic from test logic
  • Explicit Waits: Handling dynamic content loading
  • Test Fixtures: Reusable test setup and teardown
  • Test Markers: Organizing and filtering tests
  • Configuration Management: Environment-based settings
  • Error Handling: Robust test execution

🀝 Contributing

This is a learning project. Feel free to:

  • Add more test cases
  • Improve existing tests
  • Enhance page objects
  • Add new features

πŸ“„ License

This project is for educational purposes.

πŸ‘€ Author

Egemen Güney KOÇ

πŸ”— Links

πŸ™ Acknowledgments

  • Selenium WebDriver community
  • Pytest framework maintainers

πŸ“ Demo Site

This project includes a complete demo e-commerce site (demo-site/) for testing purposes. The demo site includes:

  • βœ… Login/authentication system
  • βœ… Product search functionality
  • βœ… Shopping cart with add/remove/update
  • βœ… Complete checkout process
  • βœ… Order confirmation

All locators in the test suite are designed to work with the included demo site. The demo site uses localStorage for data persistence, so no backend server is required.

🐳 Docker Support

Run tests with Docker Compose

# Build and run tests
docker-compose up --build

# Run tests only
docker-compose run test-suite pytest tests/ -v

# Run specific test
docker-compose run test-suite pytest tests/test_login.py -v

Run with Dockerfile

# Build image
docker build -t ecommerce-test-suite .

# Run container
docker run --rm ecommerce-test-suite

πŸ”„ CI/CD Pipeline

This project includes GitHub Actions CI/CD pipeline that:

  • βœ… Runs tests on multiple Python versions (3.8-3.12)
  • βœ… Tests on multiple browsers (Chrome, Firefox)
  • βœ… Generates test reports and coverage
  • βœ… Runs code quality checks (Black, Flake8, Pylint)
  • βœ… Uploads test artifacts

The pipeline runs automatically on:

  • Push to main or develop branches
  • Pull requests to main or develop branches

View the workflow file: .github/workflows/ci.yml

πŸ“Š Test Coverage

Generate coverage report:

# Install coverage tool
pip install pytest-cov

# Run tests with coverage
pytest --cov=pages --cov=utils --cov-report=html --cov-report=term

# View HTML report
open htmlcov/index.html

πŸ› οΈ Code Quality

Pre-commit Hooks

Install and use pre-commit hooks for code quality:

# Install pre-commit
pip install pre-commit

# Install hooks
pre-commit install

# Run hooks manually
pre-commit run --all-files

Code Formatting

# Format code with Black
black .

# Check formatting
black --check .

Linting

# Run Flake8
flake8 .

# Run Pylint
pylint pages/ utils/ tests/

πŸ“ Logging

The project includes centralized logging. Logs are saved to logs/ directory with timestamps.

from utils.logger import get_logger

logger = get_logger()
logger.info("Test started")
logger.error("Test failed")

🎯 Best Practices Implemented

This project demonstrates:

  • βœ… Page Object Model (POM) - Separation of concerns
  • βœ… Explicit Waits - Robust element location
  • βœ… Configuration Management - Environment-based settings
  • βœ… Test Fixtures - Reusable setup/teardown
  • βœ… Test Markers - Test organization and filtering
  • βœ… Screenshot on Failure - Debugging support
  • βœ… Multiple Browser Support - Cross-browser testing
  • βœ… Parallel Execution - Faster test runs
  • βœ… CI/CD Integration - Automated testing
  • βœ… Docker Support - Containerized testing
  • βœ… Code Quality Tools - Maintainable codebase
  • βœ… Comprehensive Logging - Better debugging

Note: This test suite is designed to work with the included demo site. To test other e-commerce sites, update locators in the page objects according to your target application.

About

Robust QA automation suite designed to streamline testing of e-commerce platforms, ensuring reliability, scalability, and performance.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published