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
Metadata
Release files for playwright-smart-locators 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| playwright_smart_locators-0.1.0.tar.gz | 69.3 kB | Without provenance | Details for playwright_smart_locators-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| playwright_smart_locators-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for playwright_smart_locators-0.1.0-py3-none-any.whl |
Total release size: 91.9 kB
Release files / playwright_smart_locators-0.1.0.tar.gz
| Download URL | playwright_smart_locators-0.1.0.tar.gz |
|---|---|
| Size | 69.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a434db8caac8ddad32247fe4035febc8b47310b4dc1bf1b4df689eb8525eb7c2
|
|
BLAKE2b-256 checksum How to use checksums |
25d1d99101873b59d6f84fa587c1fd4e724b5421e16022575f16a3a5d5fa2a6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / playwright_smart_locators-0.1.0-py3-none-any.whl
| Download URL | playwright_smart_locators-0.1.0-py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97e32a5d9e0795965064ecb064b225783766ce9071723c42085c68548ccd6081
|
|
BLAKE2b-256 checksum How to use checksums |
1f6ac65aff22630c745d417a3c4447cc4c11aa10c6daf7c90f8bd90ed9aa751e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for playwright-smart-locators 0.1.0
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.