Skip to content

Web Test Automation using Python for Beginners : Playwright + PyTest + Allure + GitHub Actions

License

Notifications You must be signed in to change notification settings

hbkandhi12/playwright-python-tests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7b36bc1 Β· Feb 5, 2025

History

40 Commits
Feb 5, 2025
Jan 23, 2025
Jan 23, 2025
Jan 9, 2025
Feb 5, 2025
Jan 23, 2025
Feb 5, 2025
Feb 5, 2025
Jan 21, 2025
Jan 27, 2025
Feb 5, 2025
Feb 5, 2025
Feb 5, 2025
Feb 5, 2025
Jan 23, 2025

Repository files navigation

Playwright-Python-tests - Automated Testing with Playwright & Python

GitHub stars GitHub forks GitHub issues

Automate your web testing using Playwright and Python. This project provides end-to-end testing capabilities with pytest and Playwright for modern web applications.


πŸš€ Features

  • βœ… Fast & Reliable Browser Automation with Playwright
  • βœ… Headless Mode for running tests in the background
  • βœ… Cross-Browser Support (Chromium, Firefox, WebKit)
  • βœ… Easy Configuration using pytest
  • βœ… Parallel Test Execution
  • βœ… Allure Reports for Test Insights

πŸ“Œ Prerequisites

Make sure you have the following installed:

  • Python 3.7+
  • Node.js (for Playwright CLI)
  • poetry package manager

βš™οΈ Installation

Clone the repository and install dependencies:

# Clone the repository
git clone https://github.com/hbkandhi12/playwright-python-tests.git
cd playwright-python-tests

# Install dependencies using Poetry
poetry install

# Install Playwright browsers
poetry run playwright install

πŸš€ Running Tests

Run Playwright tests using pytest:

poetry run pytest --headed  # Runs tests with a visible browser
poetry run pytest --headless  # Runs tests in headless mode (faster)

Run tests in parallel:

poetry run pytest -n auto  # Runs tests in parallel using multiple CPU cores

Generate an Allure Report:

poetry run pytest --alluredir=allure-results
poetry run allure generate allure-results -o allure-report --clean

You can view the latest test results in the [Allure Test Report]

## Build Status

![Build Status](https://img.shields.io/github/workflow/status/hbkandhi12/playwright-python-tests/Playwright%20-%20Pytest%20automation%20suite)

## Allure Test Report

You can view the latest test results in the [Allure Test Report](https://hbkandhi12.github.io/playwright-python-tests).

πŸ“ Project Structure

playwright-python-tests/
│── tests/
β”‚   β”œβ”€β”€ test_login.py       # Login page test cases
β”‚   β”œβ”€β”€ test_checkout.py    # Checkout workflow tests
β”‚
│── pages/
β”‚   β”œβ”€β”€ login_page.py       # Page Object Model for login page
β”‚   β”œβ”€β”€ inventory_page.py   # Page Object Model for inventory
β”‚
│── conftest.py             # Pytest fixtures
│── pyproject.toml          # Poetry configuration file
│── README.md               # Project documentation

πŸ› οΈ GitHub Actions for Allure Reports

To automatically generate and deploy Allure Reports on GitHub Pages, add the following GitHub Actions workflow:

Create .github/workflows/allure-report.yml and add:

name: Playwright Tests & Allure Report

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Install Poetry
        run: pip install poetry

      - name: Install dependencies
        run: poetry install

      - name: Install Playwright browsers
        run: poetry run playwright install

      - name: Run tests and generate Allure results
        run: poetry run pytest --alluredir=allure-results

      - name: Generate Allure Report
        run: |
          poetry run allure generate allure-results -o allure-report --clean

      - name: Deploy Allure Report to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./allure-report

Make sure GitHub Pages is enabled in your repo settings under Settings > Pages and set it to deploy from gh-pages branch.


πŸ› οΈ Contributing

Want to improve this project? Contributions are welcome! πŸš€

Steps to Contribute:

  1. Fork the repository
  2. Create a new branch (feature-branch)
  3. Commit your changes (git commit -m 'Add new feature')
  4. Push to the branch (git push origin feature-branch)
  5. Open a Pull Request

πŸ“’ Community & Support

Have a question or feature request? Create an issue or start a GitHub discussion!


πŸ“œ License

This project is licensed under the MIT License.


⭐ If you find this project helpful, please give it a star to support development! ⭐