Skip to content

chenhaijun02/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

Articles Written About This Project

Project Setup

  • Install scoop
  • Install allure commandline by running the following command:
scoop install allure
  • Clone the project
  • Navigate to the project directory
  • Install virtualenv:
py -m pip install --user virtualenv
  • Create a virtual environment:
py -m venv env
  • Activate the virtual environment:
.\env\Scripts\activate
  • Install project dependencies:
poetry install --no-root

need to create .env file in the project root with the following properties:

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 --browser <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

  • View allure results locally:
allure serve allure-results

View Help And Custom CLI Options

pytest --help

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%