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()
Providing "Intent" Context (V2)
MaxHeal works best when it knows what the user is trying to accomplish. You can inject this intent directly into the AI's brain using the built-in max_step context manager.
from max_heal import max_step
def test_login(page):
with max_step("User fills out the login form with admin credentials"):
page.fill("#user", "admin")
page.fill("#pass", "secret")
with max_step("User clicks the submit button"):
page.click(".btn-primary")
If a selector fails anywhere inside a max_step block, that exact description is routed to the LLM to help exactly pinpoint the missing button or field!
Inline Intents
You can also pass intent= directly to actions for laser-focused precision:
page.click("#submit", intent="The login button on the top right corner")
Native Allure Integration
If your framework already uses allure.step, you don't even need to rewrite your code to use max_step. MaxHeal ships with a native Allure plugin that automatically parses your existing Allure steps and feeds them to the LLM.
Simply enable it in your MaxHealConfig:
MAXHEAL_CONFIG = MaxHealConfig(
api_key="...",
use_allure=True # Automatically syncs allure.step() into MaxHeal's LLM context!
)
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) |
use_allure |
False |
Hook allure.step into LLM context |
Concurrency & Thread-Safety (pytest-xdist)
MaxHeal is 100% thread-safe and async-safe.
All intents, steps, and global_context mutations are securely bound using Python's native ContextVars. This means you can run hundreds of UI tests concurrently using pytest -n 16 or asyncio.gather(), and the LLM contexts will never leak or cross-pollinate between test workers!
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file max_heal-0.2.3.tar.gz.
File metadata
- Download URL: max_heal-0.2.3.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6d5fafa42fd64d3df7012034bf22f2e9276237b81cd8ff4e78f98702814eb10
|
|
| MD5 |
473ca5bc57e5fcd48d8e28e6c064adcc
|
|
| BLAKE2b-256 |
89b4413ebf0b093bf534348bd8075c4d6b16d21037d05b741ab506433e31db38
|
Provenance
The following attestation bundles were made for max_heal-0.2.3.tar.gz:
Publisher:
publish-pypi.yml on hadiindrawan/max-heal-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
max_heal-0.2.3.tar.gz -
Subject digest:
b6d5fafa42fd64d3df7012034bf22f2e9276237b81cd8ff4e78f98702814eb10 - Sigstore transparency entry: 1064842871
- Sigstore integration time:
-
Permalink:
hadiindrawan/max-heal-py@9049db02c92b4e57e15967730bcdfbfb5a9f819d -
Branch / Tag:
refs/tags/0.2.3 - Owner: https://github.com/hadiindrawan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@9049db02c92b4e57e15967730bcdfbfb5a9f819d -
Trigger Event:
release
-
Statement type:
File details
Details for the file max_heal-0.2.3-py3-none-any.whl.
File metadata
- Download URL: max_heal-0.2.3-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7d4acf9d72a10753fba5712513cba8d8d645b5f597e7145242390685f12b8b6
|
|
| MD5 |
9bd47742b17e93a8b525b763b2d7756d
|
|
| BLAKE2b-256 |
904b8a52ed66de9b315fff0390f0d74b2db427c68840d07d5e0fe3e1c9ffe46a
|
Provenance
The following attestation bundles were made for max_heal-0.2.3-py3-none-any.whl:
Publisher:
publish-pypi.yml on hadiindrawan/max-heal-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
max_heal-0.2.3-py3-none-any.whl -
Subject digest:
b7d4acf9d72a10753fba5712513cba8d8d645b5f597e7145242390685f12b8b6 - Sigstore transparency entry: 1064842900
- Sigstore integration time:
-
Permalink:
hadiindrawan/max-heal-py@9049db02c92b4e57e15967730bcdfbfb5a9f819d -
Branch / Tag:
refs/tags/0.2.3 - Owner: https://github.com/hadiindrawan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@9049db02c92b4e57e15967730bcdfbfb5a9f819d -
Trigger Event:
release
-
Statement type: