Skip to content

maheshmaddala1987/Selenium-Python-Example

 
 

Repository files navigation

Selenium Python Example

twitter dev run nightly Imports: isort Code style: black

Tech Stack

Tool Description
selenium A powerful tool for automating web browsers and conducting web tests
pytest A popular testing framework for Python
pytest-base-url Pytest plugin for setting a base URL for your tests
python-dotenv Loads environment variables from a .env file, simplifying configuration
mailinator-python-client A Python client for interacting with the Mailinator email service
visual-regression-tracker Performs visual regression testing
pytest-check Provides additional checking functionality for your Pytest tests
pytest-rerunfailures Pytest plugin to rerun failed tests automatically
allure-pytest Integrates Allure reporting with your Pytest tests for better reporting
requests A versatile library for making HTTP requests in Python
tenacity Retrying library
pytest-dependency Pytest plugin that allows declaring dependencies between tests
Deprecated A library for emitting warnings about deprecated code
dataclasses-json A library for serialization of dataclasses to and from JSON
mysql-connector-python Interface for connecting to MySQL databases and executing SQL queries

Articles Written About This Project

Setup Instructions

Step 1: Clone the project

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

Step 2: 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

Step 3: Install Poetry

pip install poetry

Step 4: Install Project Dependencies

poetry install --no-root

Step 5: 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

Bump Pre Commit Hooks Version

pre-commit autoupdate

Run Pre Commit Checks Manually On The Entire Project

pre-commit run --all-files

About

Selenium Python example project with pytest and Allure report

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%