Skip to content

dmberezovskyii/pytest-python-selenium-framework

Repository files navigation

Simple Python Selenium UI Automation Framework

A simple UI automation framework built with:

  • Python: 3.9 - 3.12
  • pytest: 8.3.0
  • Selenium: 4.24.0
  • CI: GitHub Actions

LinkedIn

Features

  • User-friendly UI automation framework.
  • Built on popular Python libraries: pytest and Selenium.
  • Supports Chrome, Firefox, and Remote browsers for UI testing.
  • Utilities for setting up and managing WebDriver instances.
  • Integrated with GitHub Actions CI workflow for Darwin (Mac) and Linux.
  • Supports multiple environments: dev, stage.
  • Generates pytest reports and custom logs.

Getting Started

Prerequisites

  • Python 3.8 - 3.12
  • If you're not using macOS with ARM64 architecture or a Selenium version below 4.24.0, please upload the appropriate driver corresponding to your OS to the resources directory.

Local Usage

  1. Clone this repository:

    git clone <repository-url>
  2. Install required dependencies:

    pip install poetry
    poetry shell
    poetry install
  3. Create a .env file and add:

    DEV_URL = "your-dev-project-url"
    STAG_URL = "your-staging-project-url"
    
    • Rename the chromedriver to local if you want to run tests locally.
  4. If you prefer not to use environment variables, add your references to the properties file:

    class Properties:
        _ENV_VARIABLES = {
            "dev": ("DEV_URL", ""),
            "stag": ("STAG_URL", ""),
            # Add more environments and their default URLs as needed
        }

Latest Drivers

  • You can download the latest version of the driver for macOS ARM64 using the chromedriver.sh script located in the resources folder.

TODO

Item Status
1. Drivers factory: local, remote, [Chrome, Firefox] Status
2. pytest.ini config: addopts, errors, markers Status
3. Environments: dev, stag, prod Status
4. Secrets Status
5. Utilities: YAML reader, logger Status
6. BasePage: wait strategy, base actions Status
7. Properties: make properties helper Status
8. CI: GitHub Actions: run tests, publish reports, take screenshots on failure (check test summary artifacts) Status

CI: GitHub Actions

Important Notes

  • When running CI locally, ensure your Git resources contain the correct Chrome driver with x86_64 architecture (unless using Selenium version 4.24.0 or higher).
  • Go to Repository Settings -> Secrets and Variables -> Actions -> Variables, and add DEV_URL, STAG_URL.
  • CI configuration is available for running tests on Ubuntu in run_test_ubuntu.yaml.
  •  jobs:
        selenium-tests:
          runs-on: macos-latest
          env:
            DEV_URL: ${{ vars.DEV_URL }}
            STAG_URL: ${{ vars.STAG_URL }}
    

Local: Ruff Lint Configuration

The linting configuration defines rules that dictate the checks performed. Customize these rules to suit your project's coding style and requirements.

  1. Create external tools to run linting.
  2. Set the working directory to:
    $ProjectFileDir$
    
  3. Specify the program:
    path to your ruff installed /bin/ruff 
    
  4. Provide the arguments:
    $FilePathRelativeToProjectRoot$ --config .ruff.toml