Skip to main content

A simple CLI to create a Selenium POM project structure.

Project description

Python Selenium Automation Framework

Overview

This is a professional and robust base for a Python Selenium automation framework, built using the Page Object Model (POM) design pattern. It provides a solid foundation for creating scalable and maintainable web automation scripts.

The framework is designed to be easily extensible. You can add new page objects, tests, and utility functions to suit your specific needs.

Features

  • Page Object Model (POM): A design pattern that creates a clear separation between test code and page-specific code.
  • Cross-Browser Support: Easily run tests on Chrome, Firefox, and Edge.
  • Explicit Waits: Uses WebDriverWait to handle dynamic elements, avoiding unreliable time.sleep() calls.
  • Centralized Driver Management: A DriverFactory to manage WebDriver instances.
  • Dependency Management: All required packages are listed in requirements.txt.
  • Professional Structure: A clean and organized project structure that is easy to understand and maintain.

Project Structure

.
├── config/
│   └── config.py
├── pages/
│   ├── __init__.py
│   └── base_page.py
├── utils/
│   ├── __init__.py
│   └── driver_factory.py
├── .gitignore
├── main.py
└── requirements.txt
  • config/: Contains configuration files, such as URLs, credentials, and other settings.
  • pages/: Contains page object classes. Each class represents a page in the web application and contains the locators and methods for interacting with that page.
  • utils/: Contains utility classes and functions, such as the DriverFactory for creating WebDriver instances.
  • main.py: The entry point of the application.
  • requirements.txt: A file listing the Python packages required for the project.
  • .gitignore: Specifies which files and directories to ignore in a Git repository.

Getting Started

Prerequisites

  • Python 3.6+
  • pip (Python package installer)

Installation

  1. Clone the repository:

    git clone <your-repo-url>
    cd <your-repo-directory>
    
  2. Create a virtual environment (recommended):

        # Create a virtual environment
        python -m venv .venv
    
        # Activate the virtual environment:
    
        # On Mac/Linux:
        source .venv/bin/activate
    
        # On Windows:
    
        # Git Bash:
        source .venv/Scripts/activate
    
        # CMD:
        .venv\Scripts\activate.bat
    
        # PowerShell:
        .venv\Scripts\Activate.ps1
    
  3. Install the dependencies:

    pip install -r requirements.txt
    

Running the Automation

To run the automation script, execute the main.py file from the root directory:

python main.py

The script will prompt you to enter a URL and choose a browser (chrome, firefox, or edge).

Page Object Model (POM)

This framework uses the Page Object Model (POM), which is a design pattern that enhances test maintenance and reduces code duplication. In POM, each web page in the application is represented as a class. This class contains the locators for the elements on the page and the methods to interact with those elements.

The pages/base_page.py file contains a BasePage class from which all other page object classes should inherit. This base class includes common methods like finding elements, clicking, sending keys, etc., using explicit waits for robustness.

Dependencies

  • selenium: The main library for browser automation.
  • webdriver-manager: A library that automatically manages the binaries for web drivers (e.g., chromedriver, geckodriver).

sel-pom: Selenium POM Project Creator

sel-pom is a command-line tool to quickly set up a new Python Selenium automation project using the Page Object Model (POM) architecture.

Features

  • Generate Projects Instantly: Create a new, professionally structured Selenium project with a single command.
  • Page Object Model (POM): The generated project follows the POM design pattern for maintainable and scalable automation.
  • Best Practices: Includes built-in support for explicit waits, cross-browser testing, and dependency management.

Installation

You can install sel-pom directly from this repository for local use.

  1. Clone the repository:

    git clone <your-repo-url>
    cd sel-pom-creator # Or your project's root folder
    
  2. Install in editable mode: This command installs the package on your system, and any changes you make to the source code will be immediately available.

    pip install -e .
    

Usage

Once installed, you can create a new project by running:

sel-pom new <your-project-name>

Replace <your-project-name> with the desired name for your new project. This will create a new directory with the following structure:

<your-project-name>/
├── config/
│   └── config.py
├── pages/
│   ├── __init__.py
│   └── base_page.py
├── utils/
│   ├── __init__.py
│   └── driver_factory.py
├── .gitignore
├── main.py
└── requirements.txt

Running Your New Project

To run the automation script in your newly created project:

  1. Navigate to the project directory:

    cd <your-project-name>
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Run the main script:

    python main.py
    

The script will prompt you to enter a URL and choose a browser.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sel_pom-0.0.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sel_pom-0.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file sel_pom-0.0.1.tar.gz.

File metadata

  • Download URL: sel_pom-0.0.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for sel_pom-0.0.1.tar.gz
Algorithm Hash digest
SHA256 84557244d1d8b6c9a7ef4013af6066ef5be7cf35644ee7ecacbabe75c09b4c2b
MD5 66fa55f1985ec2e528ede059e5e4d521
BLAKE2b-256 5ceffcb408b916c00e7475fd78702493b855ba3b7f5f1c4f798ad5010faec698

See more details on using hashes here.

File details

Details for the file sel_pom-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sel_pom-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for sel_pom-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f78f0e76c92aefb0cd51f4cc758daa43af033cf5157c50f84b73b3831f460625
MD5 8c18cff4509b20e3807fcdb611d14f79
BLAKE2b-256 5119dbd4dba92b29bfdd640011305fd2e64bfd584923663c17a51153e5bdd461

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page