Skip to content

VirtoCommerce/playwright-e2e-autotests

Repository files navigation

Playwright + Python Project Setup

Prerequisites

  1. Install Cursor AI (recommended IDE)
  2. Clone/download project and open with Cursor AI (or PyCharm)

Make sure you have the following installed on your system:

  • Python (version 3.7 or later)
  • pip (Python package manager)
  1. Create and activate a virtual environment

    python -m venv .venv
    source venv/bin/activate  # On macOS/Linux
    venv\Scripts\activate     # On Windows
  2. Install dependencies

    pip install playwright pytest
    python -m pip install --upgrade pip
    pip install -r requirements.txt   
  3. Install pre-commit hooks

    pre-commit install

    Note: This step needs to be done manually after installing requirements. Pre-commit hooks (including Black formatter) cannot be installed automatically through requirements.txt as this is a Git security feature.

  4. Install Playwright browsers

    playwright install
  5. Verify Playwright installation

    python -c "import playwright; print(playwright.__version__)"

Running Tests

To execute your Playwright tests with pytest, run:

pytest
# Run all tests in the file
# Example:
pytest tests/test_auth.py

# Run a specific test
pytest tests/test_auth.py -k test_user_registration
pytest tests/test_auth.py -k test_user_login

# Run with more detailed output
pytest tests/test_auth.py -v

If you want to run Playwright tests in headed mode (with browser UI), use:

pytest --headed

For running tests in a specific browser, specify it as follows:

pytest --browser=chromium  # or firefox, webkit

Environment Variables

To store authentication tokens and other secrets securely, create a .env file:

TOKEN=your_auth_token_here

Then, load environment variables in your test files using:

import os
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv("TOKEN")

Debugging Tests

  • Use --slowmo to slow down execution for debugging:
    pytest --headed --slowmo=500  # 500ms delay between steps
  • Run tests in debug mode:
    pytest --headed --debug

Generating Tests Automatically

Playwright can generate tests for you by recording actions:

playwright codegen example.com

This opens a browser where you can perform actions, and Playwright generates the corresponding test script.

Additional Resources

Happy Testing! 🚀

About

playwright-e2e-autotests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages