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
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.1.1.tar.gz.
File metadata
- Download URL: max_heal-0.1.1.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40fdb4a9a685da7bc83658fd051245418580e343538bd7d60f21e17840c571ff
|
|
| MD5 |
f30d23af324ca5d38687ff23bcd3efd3
|
|
| BLAKE2b-256 |
d40ca974d2b4d984194b1f68a702a32fbfed14d51b319233d3aab37c5ffd9df5
|
File details
Details for the file max_heal-0.1.1-py3-none-any.whl.
File metadata
- Download URL: max_heal-0.1.1-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf8199e36e69577a09122195a0e3a09b6312a334324dad85253616c95271b4e5
|
|
| MD5 |
476a1c9a384061ba804f0228ae69c708
|
|
| BLAKE2b-256 |
e5fd34e1a1effc867828e109b351bf84825be0867094800a1f6549541d0b6d6f
|