Skip to content

Playwright Python example project with pytest and Allure report

License

NotificationsYou must be signed in to change notification settings

nirtal85/Playwright-Python-Example

🎭 Playwright Python Example 🎭

twitterYouTube Channeldev runnightlyuvRuff

Automation College - Playwright Python Course

πŸ“ƒ Articles written about this project

πŸ› οΈ Tech Stack

ToolDescription
allure-pytestAllure reporting with your Pytest tests for better reporting
axe-playwright-pythonPython library for running accessibility checks with Playwright
playwrightPython library to automate the Chromium, WebKit, and Firefox browsers through a single API.
pytestPopular testing framework for Python
pytest-base-urlPytest plugin for setting a base URL for your tests
pytest-playwrightPytest plugin for Playwright integration for browser automation testing
pytest-splitPytest plugin which splits the test suite to equally sized sub suites based on test execution time.
requestsVersatile library for making HTTP requests in Python

🌐 Browser Testing

This project is tested with BrowserStack, enabling cross-browser and mobile testing on real devices in the cloud.

βš™οΈ Setup Instructions

Clone the project

git clone https://.com/nirtal85/Playwright-Python-Example
cd playwright-python

Create and activate a virtual environment then Install project dependencies

PowerShell installation in windows:

python -m uv venv
.venv\Scripts\Activate.ps1
python -m ensurepip --upgrade
python -m pip install uv
uv sync --all-extras --dev

For Mac:

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

Install playwright

playwright install

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

pytest

When no browser was selected then chrome will be used.

  • Run according to tags:
pytest -m <tag_name>

πŸ“Š 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 trace results:

  1. Navigate to the Playwright Trace Viewer
  2. Locate the trace file stored under the test-results folder. This file is generated after running your tests. Click on the 'Upload' button in the Playwright Trace Viewer and select your trace file.
  3. After uploading, the trace viewer will display a detailed timeline of events that occurred during your test. This includes network requests, JavaScript execution, and browser interactions. You can click on individual events for more details.

ℹ️ 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



Releases

No releases published

Sponsor this project

    Packages

    No packages published