Skip to content

Selenium Python example project with pytest and Allure report

License

NotificationsYou must be signed in to change notification settings

nirtal85/Selenium-Python-Example

Selenium Python Example

twitterYouTube Channeldev runnightlyuvRuff

πŸ“ƒ Articles written about this project

πŸ› οΈ Tech Stack

ToolDescription
allure-pytestAllure reporting with your Pytest tests for better reporting
assertpyAn expressive assertion library for Python
dataclasses-jsonA library for serialization of dataclasses to and from JSON
deprecatedA library for emitting warnings about deprecated code
mailinator-python-client-2A Python client for interacting with the Mailinator email service
mysql-connector-pythonInterface for connecting to MySQL databases and executing SQL queries
pytestA popular testing framework for Python
pytest-base-urlPytest plugin for setting a base URL for your tests
pytest-checkProvides additional checking functionality for your Pytest tests
pytest-dependencyPytest plugin that allows declaring dependencies between tests
pytest-orderingPytest plugin for ordering test functions
pytest-rerunfailuresPytest plugin to rerun failed tests automatically
pytest-splitPytest plugin which splits the test suite to equally sized sub suites based on test execution time.
python-dotenvLoads environment variables from a .env file, simplifying configuration
requestsA versatile library for making HTTP requests in Python
requests-toolbeltCollection of utilities for python-requests
seleniumA powerful tool for automating web browsers and conducting web tests
tenacityRetrying library
visual-regression-trackerPerforms visual regression testing
xlrdLibrary for reading data and formatting information from Excel files

βš™οΈ Setup Instructions

Clone the project

git clone https://.com/nirtal85/Selenium-Python-Example.git
cd selenium-python-example

Create and activate a virtual environment then Install project dependencies

For Windows:

pip install uv
uv venv
.\env\Scripts\activate
uv sync --all-extras --dev

For Mac:

python3 -m pip install uv
uv venv
source .venv/bin/activate
uv sync --all-extras --dev

Create .env File

Create a .env file in the project root directory to securely store project secrets and configuration variables. This file will be used to define key-value pairs for various parameters required by the project. Add the following properties to the .env file:

ParameterDescriptionExample Value
EMAILYour email address for authentication"[email protected]"
PASSWORDYour secret password for authentication"your_secret_password"
VRT_APIURLVisual Regression Tracker API URL"https://vrt.example.com/api"
VRT_PROJECTVisual Regression Tracker Project ID"project_id"
VRT_CIBUILDIDVisual Regression Tracker Build Number"build_number"
VRT_BRANCHNAMEVisual Regression Tracker Branch Name"main"
VRT_APIKEYVisual Regression Tracker API Key"your_api_key"
VRT_ENABLESOFTASSERTEnable Soft AssertionsTrue (or False)
MAILINATOR_API_KEYAPI Key for Mailinator service"your_mailinator_api_key"
MAILINATOR_DOMAIN_NAMEDomain name for Mailinator"your_mailinator_domain"

πŸƒβ€β™‚οΈ Running Tests

pytest --driver <firefox/chrome_headless>

When no browser was selected then chrome will be used.

  • Run according to tags:
pytest -m <tag_name> --browser <firefox/chrome_headless>

πŸ“Š Viewing Test Results

Install Allure Commandline To View Test results

For Windows:

Follow the instructions here to install Scoop.
Run the following command to install Allure using Scoop:

scoop install allure

For Mac:

brew install allure

View Results Locally:

allure serve allure-results

View Results Online:

View allure results via pages

ℹ️ View Help And Other CLI Options

pytest --help

Pre Commit

Run Pre Commit Checks Automatically

pre-commit install
pre-commit install --hook-type commit-msg

Bump Pre Commit Hooks Version

pre-commit autoupdate

Run Pre Commit Checks Manually On The Entire Project

pre-commit run --all-files

β˜• Support

If you find this project helpful, you can support my work by buying me a coffee:

Buy Me A Coffee



About

Selenium Python example project with pytest and Allure report

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

    Packages

    No packages published