Skip to main content

Playwright wrapper with LLM-powered auto-heal and flaky auto-fix

Project description

MaxHeal

Playwright wrapper with LLM-powered auto-heal and flaky auto-fix for Python.

Features

  • 🔧 Auto-heal broken selectors at runtime using an LLM (via OpenRouter)
  • 🔁 Flaky guard — smart retry decorator for unstable async tests
  • 🪶 Zero friction — drop-in wrapper around your existing Playwright page
  • Selector cache — healed selectors are reused within a session (no duplicate LLM calls)

Python Quick Start (Zero-Setup)

Install via pip:

pip install max-heal

Then, simply configure MaxHeal globally before your tests run (e.g., in a conftest.py or application setup file). MaxHeal will automatically intercept all playwright.sync_api.expect and playwright.async_api.expect calls across your entire framework.

import pytest
from playwright.sync_api import Page
from max_heal import MaxHealConfig, create_maxheal_page

# 1. Global AI Configuration
MAXHEAL_CONFIG = MaxHealConfig(
    api_key="sk-or-your-api-key",
    model="openai/gpt-4o-mini",
    max_retries=3
)

# 2. Wrap the global Playwright page fixture natively
@pytest.fixture
def page(page: Page):
    # This automatically activates the Global AssertPatch for this page
    return create_maxheal_page(page, MAXHEAL_CONFIG)

# 3. Write native tests normally — NO CODE CHANGES REQUIRED!
def test_login(page: Page):
    page.goto("https://example.com/login")
    
    # If the DOM changes and `#btn-signin` breaks, MaxHeal instantly freezes,
    # queries the LLM, injects the new selector, and retries the assert!
    from playwright.sync_api import expect
    expect(page.locator("#btn-signin")).to_be_visible(timeout=5000)
    page.locator("#btn-signin").click()

Advanced AI Context (Allure/Logs)

MaxHeal allows you to inject testing metadata directly into the LLM's brain so it understands what the automation is actually trying to do. Just populate the global_context dictionary.

from max_heal import global_context
import allure

def add_step(step_name):
    global_context["Current Test Step"] = step_name
    allure.step(step_name)

Configuration

Option Python default Description
api_key "" OpenRouter API key
model openai/gpt-4o-mini Chat model (any OpenRouter model)
base_url https://openrouter.ai/... OpenRouter base URL
max_retries 3 Heal attempts per selector failure
heal_enabled True Toggle auto-healing globally
timeout 30.0 HTTP timeout for LLM calls (seconds)

How It Works

Test Action -> Timeout Error / Strict Mode Violation
        │
        ▼
  Snapshot DOM (aria tree + HTML)
        │
        ▼
  Prompt LLM (selector + error + DOM + Context)
        │
        ▼
  Parse healed selector
        │
        ▼
  Retry Native Assertion directly with new selector
        │
        ▼
  Cache result to prevent duplicate LLM calls

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

max_heal-0.1.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

max_heal-0.1.2-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file max_heal-0.1.2.tar.gz.

File metadata

  • Download URL: max_heal-0.1.2.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for max_heal-0.1.2.tar.gz
Algorithm Hash digest
SHA256 31aaa1b2c979eaaee67c578098be0cc3e0a0fd964bf212fe607d749f7756119e
MD5 bf067e4e9b96d8956bedb16680cfd141
BLAKE2b-256 fd20862a4a0e9b45154ef7ddafba684537975667b3a76c4d880cc4808eab3bd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for max_heal-0.1.2.tar.gz:

Publisher: publish-pypi.yml on hadiindrawan/max-heal-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file max_heal-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: max_heal-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for max_heal-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7d7675f306eba61220a63abe688da5011ffdcd992d87bed62da76cb051709dcf
MD5 f56d00ba703b96faabf6ac61490caa99
BLAKE2b-256 415576f2573c06184afdf65b5cbc9a9b1ced0ea738535a0ff525598d3012214a

See more details on using hashes here.

Provenance

The following attestation bundles were made for max_heal-0.1.2-py3-none-any.whl:

Publisher: publish-pypi.yml on hadiindrawan/max-heal-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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