Loading...
Loading...
Python Playwright testing of local web apps. Use when verifying frontend functionality, debugging UI behavior, capturing browser screenshots, or viewing browser console logs.
npx skill4agent add sentimony/skills playwright-debugscripts/with_server.pydebugdebugplaywright-debugdebugplaywright-debugdebug--helpUser task → Is it static HTML?
├─ Yes → Read HTML file directly to identify selectors
│ ├─ Success → Write Playwright script using selectors
│ └─ Fails/Incomplete → Treat as dynamic (below)
│
└─ No (dynamic webapp) → Is the server already running?
├─ No → Run: python <skill>/scripts/with_server.py --help
│ Then use the helper + write simplified Playwright script
│
└─ Yes → Reconnaissance-then-action:
0. Confirm the actual port; dev servers silently move to the next port
(3000 → 3004) when the default is taken. Read the startup log, or when the
project forbids printing it (secrets), probe with `curl -sI http://127.0.0.1:<port>`
and `lsof -nP -iTCP:<port> -sTCP:LISTEN`
1. Navigate and wait for rendered content (see Waiting Strategy)
2. Take screenshot or inspect DOM
3. Identify selectors from rendered state
4. Execute actions with discovered selectors--helppython <skill>/scripts/with_server.py \
--server "npm run dev" --host 127.0.0.1 --port 5173 \
-- python your_automation.py--server--host--port--host127.0.0.1localhost127.0.0.1from playwright.sync_api import sync_playwright
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
with sync_playwright() as p:
browser = p.chromium.launch(headless=True) # Always launch chromium in headless mode
page = browser.new_page()
page.on('console', lambda msg: print(f'[console.{msg.type}] {msg.text}')) # msg.type: log, debug, info, warning, error
page.on('pageerror', lambda err: print(f'[pageerror] {err}')) # Uncaught JS exceptions are not console events
page.on('requestfailed', lambda req: print(
f'[requestfailed] {req.url} {req.failure or "unknown"}')) # failure is Optional[str] in Python; hint only - see Interpreting Failures
page.on('response', lambda res: res.status >= 400 and print(f'[http {res.status}] {res.url}'))
page.goto('http://127.0.0.1:5173', wait_until='domcontentloaded') # Server already running and ready
try:
page.wait_for_function(
"() => document.body.innerText.trim().length > 0", timeout=5000) # Wait for the SPA to render
except PlaywrightTimeoutError:
pass # text-free page (canvas/WebGL) - proceed to screenshot recon
page.screenshot(path='recon.png') # Visual state check
# ... your automation logic
browser.close()playwrightpip install playwright==1.61.0 && python -m playwright install chromiumpage.goto(url, wait_until='domcontentloaded')wait_for_function("() => document.body.innerText.trim().length > 0")"() => ..."evalscript-src 'self'EvalErrorEvalErrorpage.wait_for_selector()expect(locator)networkidlepage.wait_for_timeout(2000-3000)domcontentloadedframenavigatedcurlpage.goto()ERR_ABORTEDgotoexamples/console_audit.pytryexceptfinallyfinally/api/**page.route("**/api/**", lambda route, request: route.abort())fulfill(route, request)def handler(body): return lambda route, request: route.fulfill(json=body)lambda r, body=body: ...requestbodyObject of type Request is not JSON serializablelambda route, request, body=body: ...request.post_data_jsonroute.fulfill(path=...)json=time.sleeprouteroute.fulfill(...)fulfillafconvert -f adts -d aac silence.wav out.aacffmpeg#EXTINFargs=["--autoplay-policy=no-user-gesture-required"]console.errorwarningpageerrorrequestfailedrequestfailedERR_ABORTEDpage.close()?v=curlpage.evaluate("fetch(...)")4xx5xx[vite] connecting...Unrecognized featureloading="lazy"sync_playwright()page.get_by_role()page.get_by_label()page.get_by_text()DropdownMenuget_by_role('columnheader')page.locator('th', has_text=...)get_by_role('button', name=...).firstlocator.aria_snapshot()hrefhrefget_by_role('banner').get_by_role(...)page.wait_for_selector()expect(locator)fillpage.wait_for_url(lambda u: '/login' not in u)input_value()examples/console_audit.pyfull_page=True--servercurl -sIlsof127.0.0.1pageerrorwith_server.py--server--hrefwith_server.py--servershlex--cd … && …--server "bash -c '…'"file://curlafconvertffmpegpip install playwright==1.61.0python -m playwright install chromiumelement_discovery.pystatic_html_automation.pyconsole_logging.pyconsole_audit.pywebapp-testing