/Selenium-Python-Example

Selenium Python example project with pytest and Allure report

Primary LanguagePythonApache License 2.0Apache-2.0

Selenium Python Example

twitter YouTube Channel dev run nightly Imports: isort Code style: black

📃 Articles written about this project

🛠️ Tech Stack

Tool Description
allure-pytest Allure reporting with your Pytest tests for better reporting
assertpy An expressive assertion library for Python
dataclasses-json A library for serialization of dataclasses to and from JSON
deprecated A library for emitting warnings about deprecated code
mailinator-python-client-2 A Python client for interacting with the Mailinator email service
mysql-connector-python Interface for connecting to MySQL databases and executing SQL queries
pytest A popular testing framework for Python
pytest-base-url Pytest plugin for setting a base URL for your tests
pytest-check Provides additional checking functionality for your Pytest tests
pytest-dependency Pytest plugin that allows declaring dependencies between tests
pytest-ordering Pytest plugin for ordering test functions
pytest-rerunfailures Pytest plugin to rerun failed tests automatically
pytest-split Pytest plugin which splits the test suite to equally sized sub suites based on test execution time.
python-dotenv Loads environment variables from a .env file, simplifying configuration
requests A versatile library for making HTTP requests in Python
requests-toolbelt Collection of utilities for python-requests
selenium A powerful tool for automating web browsers and conducting web tests
tenacity Retrying library
visual-regression-tracker Performs visual regression testing
xlrd Library for reading data and formatting information from Excel files

⚙️ Setup Instructions

Clone the project

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

Create and activate a virtual environment

For Windows:

py -m pip install --user virtualenv
py -m venv env
.\env\Scripts\activate

For Mac:

python3 -m pip install --user virtualenv
python3 -m venv venv
source venv/bin/activate

Install Poetry

pip install poetry

Install Project Dependencies

poetry install --no-root

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:

Parameter Description Example Value
EMAIL Your email address for authentication "your@email.com"
PASSWORD Your secret password for authentication "your_secret_password"
VRT_APIURL Visual Regression Tracker API URL "https://vrt.example.com/api"
VRT_PROJECT Visual Regression Tracker Project ID "project_id"
VRT_CIBUILDID Visual Regression Tracker Build Number "build_number"
VRT_BRANCHNAME Visual Regression Tracker Branch Name "main"
VRT_APIKEY Visual Regression Tracker API Key "your_api_key"
VRT_ENABLESOFTASSERT Enable Soft Assertions True (or False)
MAILINATOR_API_KEY API Key for Mailinator service "your_mailinator_api_key"
MAILINATOR_DOMAIN_NAME Domain 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 Github 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