Skip to main content

AI-powered Playwright test report analyzer using PydanticAI

Project description

Playwright Test Report Analyzer 🤖

An AI-powered tool that analyzes Playwright test reports to provide intelligent insights, failure analysis, and actionable recommendations. The tool uses PydanticAI with OpenAI-compatible models to understand test failures and inject the analysis directly into your Playwright HTML reports.

Features ✨

  • Automatic Test Report Parsing: Extracts test results from Playwright HTML reports
  • AI-Powered Analysis: Uses reasoning models to analyze failures and identify patterns
  • Failure Root Cause Analysis: Identifies why tests failed with categorization
  • Pattern Recognition: Detects common failure patterns across multiple tests
  • Flaky Test Detection: Identifies tests with intermittent failures
  • Performance Insights: Highlights slow tests and performance issues
  • HTML Report Enhancement: Injects AI insights directly into the Playwright report
  • Flexible Model Support: Works with OpenAI, Ollama, or any OpenAI-compatible API

Prerequisites 🔧

  • Python 3.9 or higher
  • UV package manager

Installing UV

# Install UV (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Or using Homebrew on macOS
brew install uv

Installation 📦

Install from PyPI

# Install using pip
pip install playwright-analyzer

# Or using uv
uv pip install playwright-analyzer

Install from Source

# Clone the repository
git clone https://github.com/billaram/playwright-analyzer.git
cd playwright-analyzer

# Install dependencies using UV
uv sync

# For development dependencies
uv sync --dev

Configuration ⚙️

  1. Copy the example environment file:
cp .env.example .env
  1. Edit .env with your configuration:
# For OpenAI
OPENAI_API_KEY=your_api_key_here
MODEL_NAME=gpt-4o-mini

# For local models (e.g., Ollama)
OPENAI_API_BASE=http://localhost:11434/v1
MODEL_NAME=llama3.2

Usage 🚀

Basic Usage

After running your Playwright tests:

# Run Playwright tests first
pnpm test:e2e

# If installed from PyPI
playwright-analyzer --help

# If installed from source
cd playwright-analyzer
uv run playwright-analyzer --help

Command Line Options

playwright-analyzer --help

Options:
  --report PATH      Path to Playwright HTML report (default: ../playwright-report/index.html)
  --context PATH     Path to context file (default: ../CONTEXT-TEST.md)
  --model NAME       Model name (default: from .env or gpt-4o-mini)
  --api-key KEY      API key (default: from .env)
  --api-base URL     API base URL (default: from .env or OpenAI)
  --no-inject        Don't inject insights into HTML report

Examples

# Use GPT-4 for more detailed analysis
playwright-analyzer --model gpt-4o

# Use local Ollama model
playwright-analyzer --model llama3.2 --api-base http://localhost:11434/v1

# Analyze without modifying the HTML report
playwright-analyzer --no-inject

# Custom report path
playwright-analyzer --report /path/to/playwright-report/index.html

Integration with CI/CD 🔄

Add to your GitHub Actions workflow:

- name: Run Playwright Tests
  run: pnpm test:e2e
  continue-on-error: true

- name: Install UV
  if: always()
  uses: astral-sh/setup-uv@v2
  with:
    enable-cache: true
    cache-dependency-glob: "playwright-analyzer/pyproject.toml"

- name: Analyze Test Report
  if: always()
  run: |
    pip install playwright-analyzer
    playwright-analyzer
  env:
    OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

- name: Upload Enhanced Report
  if: always()
  uses: actions/upload-artifact@v3
  with:
    name: playwright-report-with-insights
    path: playwright-report/

Output 📊

The analyzer provides:

1. Console Output

  • Test summary statistics
  • Detailed failure analysis
  • Recommendations and patterns
  • Risk areas and performance issues

2. Enhanced HTML Report

The original Playwright report is enhanced with:

  • AI insights section with visual metrics
  • Failure analysis with root causes
  • Recommendations panel
  • Common patterns detection
  • Flaky test identification

3. JSON Export

Insights are also saved to playwright-report/ai-insights.json for programmatic access.

Architecture 🏗️

playwright-analyzer/
├── src/
│   └── playwright_analyzer/
│       ├── __init__.py          # Package initialization
│       ├── analyze_report.py    # Main CLI entry point
│       ├── report_parser.py     # Parses Playwright HTML reports
│       ├── agent.py            # PydanticAI agent for analysis
│       └── report_injector.py  # Injects insights into HTML
├── pyproject.toml              # UV/Python project configuration
├── .python-version             # Python version for UV
├── .env.example                # Environment template
└── README.md                   # This file

How It Works 🔍

  1. Report Parsing: Extracts test data from Playwright's embedded JSON
  2. Context Loading: Loads application context (optional)
  3. AI Analysis: Sends failure data to AI model for analysis
  4. Insight Generation: Creates structured insights with PydanticAI
  5. HTML Injection: Adds insights to the original report
  6. Export: Saves insights as JSON for further processing

Models Supported 🤖

  • OpenAI: GPT-4, GPT-4 Turbo, GPT-3.5 Turbo
  • Anthropic: Claude (via OpenAI-compatible API)
  • Ollama: Llama, Mistral, CodeLlama (local)
  • Any OpenAI-compatible API

Features in Detail 📝

Failure Analysis

  • Categorizes failures (UI, Network, Timing, Logic)
  • Identifies root causes
  • Provides specific fix suggestions
  • Assesses impact level

Pattern Detection

  • Groups similar failures
  • Identifies systemic issues
  • Detects configuration problems
  • Highlights regression patterns

Performance Insights

  • Identifies slow tests
  • Detects timeout issues
  • Suggests optimization opportunities
  • Monitors test duration trends

Flaky Test Detection

  • Identifies tests with retries
  • Detects intermittent failures
  • Suggests stabilization strategies
  • Tracks flakiness patterns

Development 🧪

Running Tests

# Run tests with UV
uv run pytest

# Run with coverage
uv run pytest --cov

# Format code
uv run black .

# Lint code
uv run ruff check .

Installing Development Dependencies

# Install all dependencies including dev
uv sync --dev

Troubleshooting 🛠️

"Report file not found"

  • Ensure Playwright tests have been run: pnpm test:e2e
  • Check the report path: ls ../playwright-report/index.html

"API key is required"

  • Set OPENAI_API_KEY in .env file
  • Or use --api-key argument
  • Or use a local model with --api-base

"Could not extract test data"

  • Ensure you're using a recent version of Playwright
  • Check that the HTML report contains embedded JSON data

"Module not found" errors

  • Ensure UV is installed: brew install uv or curl -LsSf https://astral.sh/uv/install.sh | sh
  • Run uv sync to install dependencies
  • Use uv run prefix for all Python commands

Contributing 🤝

Contributions are welcome! Areas for improvement:

  • Support for more test frameworks
  • Additional analysis patterns
  • Performance optimizations
  • More model integrations

License 📄

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playwright_analyzer-0.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

playwright_analyzer-0.1.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file playwright_analyzer-0.1.0.tar.gz.

File metadata

  • Download URL: playwright_analyzer-0.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for playwright_analyzer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 75cd6a7627b4ec709468c9bfb1e1f9576941ec20d01768bd3d1b429f4b41cd5c
MD5 ac6598283afe6a17a8397ea3ac04b6df
BLAKE2b-256 64954e034dbfe0148fb5e16b6aabf6e0dd590a0c1baa08cc81e5006db6f4a80d

See more details on using hashes here.

File details

Details for the file playwright_analyzer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for playwright_analyzer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb74ea25affe326e5556f7d7805464f672ac15995d129bf12ed45280e91967ed
MD5 310d84d76044a256e4e2eb18a2a86573
BLAKE2b-256 2873bd109c065846024b2946998f134a7fc2356411d25172723409871a95a69a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page