Skip to main content

🩺 Self-Healer

AI-powered self-healing pytest plugin for Playwright — automatically detects broken selectors in your tests and uses LLM reasoning to suggest (and optionally apply) fixes.

PyPI version Python 3.10+ License: MIT


✨ What It Does

When a Playwright test fails because a CSS selector or XPath no longer matches an element:

  1. Detects the broken selector and extracts the relevant DOM context
  2. Reasons about what the selector was supposed to do (using Groq/LLM)
  3. Suggests a corrected selector with confidence score
  4. Shows a rich TUI panel with the suggestion
  5. Applies the fix directly to your source code (with your approval!)

All of this happens automatically — just install and run your tests.


🚀 Quick Start

Step 1: Install

pip install self-healer

Step 2: Set Environment Variables

# Required
API_KEY="sk_..."
LLM_MODEL="openai/gpt-4.1-mini"

# Optional (these have defaults)
BASE_URL="https://api.openai.com"
TEMPERATURE="0.4"

Step 3: Add to your conftest.py

# conftest.py
import pytest
from playwright.sync_api import sync_playwright

from dotenv import load_dotenv
load_dotenv()
from self_healer import enable_healing


@pytest.fixture(scope="session")
def page():
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()

        enable_healing(page)                    # ← Enable self-healing
        
        page.goto("https://www.your-app.com/")
        yield page
        browser.close()

Step 4: Write Tests (normal Playwright)

# tests/test_login.py
from playwright.sync_api import Page

def test_login(page: Page):
    page.fill("#user-name", "admin")
    page.fill("#password", "secret")
    page.click("#login-button")
    assert "dashboard" in page.url

Step 5: Run

pytest -v

If #login-button changes to #btn-login, the agent will:

  • Detect the failure
  • Analyze the live DOM
  • Suggest #btn-login with high confidence
  • Ask you to Accept, Reject, or Copy the fix

⚙️ Configuration

All configuration is via environment variables — no config files needed.

Variable Required Default Description
API_KEY ✅ — Your API key
LLM_MODEL ✅ — LLM model name
BASE_URL ❌ https://api.openai.com API endpoint URL
TEMPERATURE ❌ 0.4 LLM temperature (0.0–1.0)

🏗️ How It Works

                Test Fails (broken selector)
                    │
                    ▼
            ┌─────────────────┐
            │  Detect Failure │  pytest hook intercepts the error
            └────────┬────────┘
            ┌────────┴─────────┐
            ▼                  ▼
┌─────────────────┐     ┌──────────────────┐
│  DOM Extractor  │     │   XPath Builder  │  (for dynamic sites)
└────────┬────────┘     └────────┬─────────┘
         └───────────┬───────────┘
                     ▼
            ┌──────────────────┐
            │  LLM Reasoning   │  Groq/LLaMA analyzes intent + DOM
            └────────┬─────────┘
                     ▼
            ┌──────────────────┐
            │  File Locator    │  Finds exact file:line of selector
            └────────┬─────────┘
                     ▼
            ┌──────────────────┐
            │ Human Approval   │  Rich TUI: Accept / Reject / Copy
            └────────┬─────────┘
            ┌────────┴─────────┐
           Yes                 No
            │                  │
            ▼                  ▼
    ┌────────────────┐ ┌───────────────┐
    │    Apply Fix   │ │  Reject Fix   │
    └────┬───────────┘ └───────┬───────┘
         └──────────┬──────────┘
                    ▼
                ┌─────────┐
                │   END   │
                └─────────┘

📦 For Package Developers

Building from source

git clone https://github.com/ankan01-cbnits/self_healing_agent.git
cd self-healing_agent
uv sync
uv build

Publishing to PyPI

# Test on TestPyPI first
pip install twine
twine upload --repository testpypi dist/*

# Then publish to real PyPI
twine upload dist/*

📄 License

MIT License — see LICENSE for details.

Metadata

Release files for self-healer 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for self-healer 1.0.1
File Size Uploaded Provenance Actions
self_healer-1.0.1.tar.gz 28.2 kB Without provenance Details for self_healer-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for self-healer 1.0.1
File Interpreter ABI Platform Actions
self_healer-1.0.1-py3-none-any.whl Python 3 none any Details for self_healer-1.0.1-py3-none-any.whl

Total release size: 66.0 kB

Release files / self_healer-1.0.1.tar.gz

Download URL self_healer-1.0.1.tar.gz
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bf97624b086f26a0dfc001884c296169bb9850709c1fa7f17b1543fdda508054
BLAKE2b-256 checksum
How to use checksums
ec5c8c4c3e14233a492cb2b869f7c9e53eb3cc171391db9faa84a5faf9a6cbe2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / self_healer-1.0.1-py3-none-any.whl

Download URL self_healer-1.0.1-py3-none-any.whl
Size 37.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0b9604ff55915a1842c750b43c41dfd26f5d180ce8824da64c668c23b63c608
BLAKE2b-256 checksum
How to use checksums
6040b547d41740e4d856c229653a91e94516556a7b3ab6ebbc946edf5647ef25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for self-healer 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page