playwright-pom-agent
Generates Playwright Python Page Object Model classes from a live page, using an LLM to propose locators and a live verification loop to make sure every locator it writes is actually unique on the page before it's used.
Data sent to the LLM provider
Generation sends the page's accessibility tree (roles, visible text, structure) and a small test-id attribute inventory (tag + attribute value + a short text snippet) to your configured LLM provider (Anthropic or OpenAI). It does NOT read cookies, local/session storage, or form field values. If a page visibly displays sensitive info (names, account numbers, etc.), that text is included in what's sent - review before running against such pages. The CLI prints this notice on every run; it doesn't block execution.
Locator priority
get_by_test_id()(data-testid, or a custom attribute via--test-id-attribute)get_by_role()get_by_label()get_by_placeholder()get_by_text()get_by_alt_text()/get_by_title()#idCSS selector[name="..."]CSS selector- Generic CSS / XPath (last resort)
Every candidate is verified with .count() == 1 on the live page before
being written to the generated file. Ambiguous or unresolved elements are
retried (default: 3 attempts, via .filter(has_text=...) or parent scoping)
before being emitted with an # UNVERIFIED comment rather than looping
forever.
Dynamic UI state (modals, dropdowns, accordions)
Only the DOM present at inspection time is visible. This tool does not auto-crawl interactions. To document elements behind an interaction:
- CLI: pass
--setup-script path/to/setup.py, a file definingdef setup(page): ...that runs after navigation and before inspection (e.g. click to open a modal). - Programmatic API: drive
pageinto the desired state yourself before callingPOMAgent.generate(page).
Generated files
Generated POM files start with an # AUTO-GENERATED ... DO NOT EDIT header.
Re-running generation overwrites the file completely - put custom logic in a
subclass, not in the generated file.
CLI
Set ANTHROPIC_API_KEY or OPENAI_API_KEY (matching --provider) before
running - the CLI also accepts --api-key directly, but the env var is
preferred since CLI arguments can leak via shell history and process listings.
export ANTHROPIC_API_KEY=sk-...
pom-agent generate --url https://example.com/login \
--out example_login_page.py \
--test-id-attribute data-pw \
--provider anthropic
Programmatic
from playwright.sync_api import sync_playwright
from playwright_pom_agent import POMAgent
with sync_playwright() as p:
page = p.chromium.launch().new_page()
page.goto("https://example.com/login")
agent = POMAgent(provider="anthropic")
code = agent.generate(page, out_path="login_page.py")
Testing
uv pip install -e ".[dev]"
pytest tests/
tests/test_fixtures/ runs against local HTML fixtures in tests/fixtures/.
tests/test_demo/test_demo_url.py is a reference suite that exercises the
whole tool against a real site - https://demo.realworld.show/, a public
"Conduit" demo app with no data-testids or <label>s anywhere, so it
genuinely tests the role/placeholder fallback tiers instead of the tier-1
shortcut most fixtures hit. It covers locator resolution across the login,
register, settings, and editor pages, plus full programmatic and CLI
generation runs that actually log in with the generated code - those runs
write their generated POM classes to tests/test_demo/pages/ (overwritten
on each run) so you can open real, working, generated output rather than
just reading assertions. Use it as a template for pointing this tool at your
own app (swap BASE_URL/TEST_EMAIL/TEST_PASSWORD, or set the
REALWORLD_* env vars it reads).
These tests are marked live and require internet access:
pytest tests/ -m "not live" # skip the live/network tests
pytest tests/ -m live # run only the live tests
One test in that file makes a real, billed LLM call and is opt-in only -
it won't run just because ANTHROPIC_API_KEY/OPENAI_API_KEY happen to be
set in your shell:
RUN_LIVE_LLM_TESTS=1 ANTHROPIC_API_KEY=sk-... pytest tests/test_demo/test_demo_url.py -k real_llm
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_pom_agent-0.1.0.tar.gz.
File metadata
- Download URL: playwright_pom_agent-0.1.0.tar.gz
- Upload date:
- Size: 71.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6e59c704961c20a163b12f6e604a9558cebc924a514325d2e9f88bfa03b3e21
|
|
| MD5 |
66ae538904e51134ed1fba476c6538dc
|
|
| BLAKE2b-256 |
6b306be0fbe6af22a821e57f9cb01366d5c185141a14944a0bb4b3ce64b6b3a1
|
Provenance
The following attestation bundles were made for playwright_pom_agent-0.1.0.tar.gz:
Publisher:
publish.yml on VinayakaMayura/playwright-pom-agent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
playwright_pom_agent-0.1.0.tar.gz -
Subject digest:
b6e59c704961c20a163b12f6e604a9558cebc924a514325d2e9f88bfa03b3e21 - Sigstore transparency entry: 2530652555
- Sigstore integration time:
-
Permalink:
VinayakaMayura/playwright-pom-agent@a9f4539c596ed9b8814c094ec18c920d8563aaa1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/VinayakaMayura
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a9f4539c596ed9b8814c094ec18c920d8563aaa1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file playwright_pom_agent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: playwright_pom_agent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5927e341e35e0dc18a187aee64e75ed87fa57f262e2eeb43416e7d0d76f68665
|
|
| MD5 |
12facfb81a54fc181b36457e38b2e3ab
|
|
| BLAKE2b-256 |
b065a75d8421f042d1aba5d05f972e579f7b2a9f00e2b404628fcabeb7905d5f
|
Provenance
The following attestation bundles were made for playwright_pom_agent-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on VinayakaMayura/playwright-pom-agent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
playwright_pom_agent-0.1.0-py3-none-any.whl -
Subject digest:
5927e341e35e0dc18a187aee64e75ed87fa57f262e2eeb43416e7d0d76f68665 - Sigstore transparency entry: 2530653024
- Sigstore integration time:
-
Permalink:
VinayakaMayura/playwright-pom-agent@a9f4539c596ed9b8814c094ec18c920d8563aaa1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/VinayakaMayura
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a9f4539c596ed9b8814c094ec18c920d8563aaa1 -
Trigger Event:
workflow_dispatch
-
Statement type: