AI-powered self-healing smart locators for Playwright (Python).
Project description
playwright_smart_locators (Python)
AI-powered self-healing smart locators for Playwright tests (Python port of @axeforging/playwright-smart-locators).
When a Playwright locator fails, playwright_smart_locators intercepts the
timeout, queries an LLM with the broken selector and live/cached DOM, and
retries with the top 7 AI-suggested locators. After the run, it writes
*-healed.py suggestion files for review.
Install
pip install playwright_smart_locators
playwright install chromium
Configure
In your conftest.py (opt-in):
import pytest
from playwright_smart_locators import smart_page
@pytest.fixture
def page(smart_page):
return smart_page
In pyproject.toml or pytest.ini:
[tool.pytest.ini_options]
addopts = [
"--enable-auto-heal",
"--ai-model=qwen2.5:7b",
"--ai-pipe-url=http://localhost:11434",
"--ai-admin-key=sk-",
]
Or via environment variables (recommended for Docker / CI):
| Env var | Default | Notes |
|---|---|---|
ENABLE_AUTO_HEAL |
false |
true / 1 / yes / on to activate |
AI_MODEL |
qwen2.5:7b |
Any model name your provider accepts |
AI_PIPE_URL |
http://localhost:11434 |
Base URL — OpenAI provider appends /v1/chat/completions |
AI_ADMIN_KEY |
(empty) | Bearer token; leave empty for local Ollama |
AI_PROVIDER |
openai |
openai or anthropic |
AI_RATE_PER_MIN |
30 |
In-process token bucket rate |
Precedence: env var > CLI flag > built-in default. Env wins so Docker / CI configs don't have to be repeated on the command line. Empty env values fall back to the CLI value (so you can set AI_ADMIN_KEY= in a .env to mean "leave unset" without overriding the CLI flag).
Provider auto-detect: if AI_PIPE_URL ends with /anthropic (e.g. https://api.example.com/anthropic), the plugin automatically sets ai_provider=anthropic and emits a UserWarning. This lets Anthropic-compatible services (like MiniMax) work without setting AI_PROVIDER=anthropic explicitly. To opt out, set AI_PIPE_URL to a path that doesn't end with /anthropic (e.g. add a suffix like /v1).
# Examples
export ENABLE_AUTO_HEAL=true
export AI_MODEL=gpt-4o
export AI_PIPE_URL=https://api.openai.com
export AI_ADMIN_KEY=sk-xxx
pytest
AI Providers
Built-in:
openai(also works with Ollama, Open WebUI, vLLM, LocalAI)anthropic
Register your own:
from playwright_smart_locators import register_provider
class MyProvider:
def complete(self, *, system, user, model, timeout=30.0) -> str:
return '{"locators": [".my-locator"]}'
register_provider("custom", MyProvider)
POM Support
When a locator fails inside a Page Object Model method, the auto-healer
uses inspect.stack() to find the real caller file/line. The
*-healed.py is written next to the POM file (e.g. pages/login_page-healed.py),
not the test spec.
CI
Disable in CI (no LLM available):
# CI: don't pass --enable-auto-heal
pytest --browser=chromium
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 playwright_smart_locators-0.1.0.tar.gz.
File metadata
- Download URL: playwright_smart_locators-0.1.0.tar.gz
- Upload date:
- Size: 69.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"arm64","distro":{"name":"macOS","version":"13.4.1"},"implementation":{"name":"CPython","version":"3.14.4"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.6.2 7 Apr 2026","python":"3.14.4","system":{"name":"Darwin","release":"22.5.0"}} HTTPX2/2.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a434db8caac8ddad32247fe4035febc8b47310b4dc1bf1b4df689eb8525eb7c2
|
|
| MD5 |
7c78d34137ac462d8a8b8af64568e13e
|
|
| BLAKE2b-256 |
25d1d99101873b59d6f84fa587c1fd4e724b5421e16022575f16a3a5d5fa2a6d
|
File details
Details for the file playwright_smart_locators-0.1.0-py3-none-any.whl.
File metadata
- Download URL: playwright_smart_locators-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"arm64","distro":{"name":"macOS","version":"13.4.1"},"implementation":{"name":"CPython","version":"3.14.4"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.6.2 7 Apr 2026","python":"3.14.4","system":{"name":"Darwin","release":"22.5.0"}} HTTPX2/2.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97e32a5d9e0795965064ecb064b225783766ce9071723c42085c68548ccd6081
|
|
| MD5 |
02e1b338fa1f8ce2339cb9236f82d4c5
|
|
| BLAKE2b-256 |
1f6ac65aff22630c745d417a3c4447cc4c11aa10c6daf7c90f8bd90ed9aa751e
|