webapp-testing
NickCrew/claude-cortex
用于通过 Playwright 与本地 Web 应用程序交互并对其进行测试的工具包。可用于验证前端功能、调试 UI 行为、捕获浏览器截图以及查看浏览器日志。
...展开全部关于webapp-testing
“webapp-testing ”技能提供了一套全面的工具集,用于通过 Playwright 与本地 Web 应用程序进行交互并对其进行测试。 该技能旨在简化前端功能的测试流程,使开发人员和测试人员能够更轻松地验证用户界面、调试行为、捕获浏览器截图以及监控浏览器日志。对于需要确保 Web 应用程序按预期运行的任何人而言,该技能都必不可少,特别是在需要仔细检查并与页面上各种元素进行交互的动态环境中。
常见问题
如何运行辅助脚本?
要运行辅助脚本,请务必先使用 '--help' 参数。这将显示使用说明。例如,运行 'python scripts/with_server.py --help' 可查看如何管理服务器生命周期。
这个工具既适用于静态 Web 应用程序,也适用于动态 Web 应用程序吗?
是的,该工具既适用于静态 HTML 页面,也适用于动态 Web 应用程序。该工具包为每种类型提供了具体的处理步骤,例如直接读取静态应用的 HTML,或管理动态应用的服务器生命周期。
是否有具体的兼容性要求?
此技能需要安装 Python 和 Playwright,并旨在用于本地 Web 应用程序。它支持多种配置,例如同时运行多个服务器以进行后端和前端测试。
使用此技能时有哪些常见陷阱?
一个常见的错误是在确认页面完全加载之前就检查 DOM。在检查或与页面交互之前,请务必使用 'page.wait_for_load_state('networkidle')' 等待 'networkidle' 状态。
我需要手动管理服务器吗?
不需要,“scripts/with_server.py”会自动管理服务器的生命周期。您可以根据后端和前端测试的需求运行多个服务器,无需手动配置。
Web Application Testing
To test local web applications, write native Python Playwright scripts.
Helper Scripts Available:
scripts/with_server.py- Manages server lifecycle (supports multiple servers)
Always run scripts with --help first to see usage. DO NOT read the source until you try running the script first and find that a customized solution is abslutely necessary. These scripts can be very large and thus pollute your context window. They exist to be called directly as black-box scripts rather than ingested into your context window.
Decision Tree: Choosing Your Approach
User 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 scripts/with_server.py --help │ Then use the helper + write simplified Playwright script │ └─ Yes → Reconnaissance-then-action: 1. Navigate and wait for networkidle 2. Take screenshot or inspect DOM 3. Identify selectors from rendered state 4. Execute actions with discovered selectorsExample: Using with_server.py
To start a server, run --help first, then use the helper:
Single server:
python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.pyMultiple servers (e.g., backend + frontend):
python scripts/with_server.py \ --server "cd backend && python server.py" --port 3000 \ --server "cd frontend && npm run dev" --port 5173 \ -- python your_automation.py
To create an automation script, include only Playwright logic (servers are managed automatically):
from playwright.sync_api import sync_playwrightwith sync_playwright() as p: browser = p.chromium.launch(headless=True) # Always launch chromium in headless mode page = browser.new_page() page.goto('http://localhost:5173') # Server already running and ready page.wait_for_load_state('networkidle') # CRITICAL: Wait for JS to execute # ... your automation logic browser.close()
Reconnaissance-Then-Action Pattern
Inspect rendered DOM:
page.screenshot(path='/tmp/inspect.png', full_page=True)content = page.content()page.locator('button').all()
Identify selectors from inspection results
Execute actions using discovered selectors
Common Pitfall
❌ Don't inspect the DOM before waiting for networkidle on dynamic apps✅ Do wait for page.wait_for_load_state('networkidle') before inspection
Best Practices
- Use bundled scripts as black boxes - To accomplish a task, consider whether one of the scripts available in
scripts/can help. These scripts handle common, complex workflows reliably without cluttering the context window. Use--helpto see usage, then invoke directly. - Use
sync_playwright()for synchronous scripts - Always close the browser when done
- Use descriptive selectors:
text=,role=, CSS selectors, or IDs - Add appropriate waits:
page.wait_for_selector()orpage.wait_for_timeout()
Reference Files
- examples/ - Examples showing common patterns:
element_discovery.py- Discovering buttons, links, and inputs on a pagestatic_html_automation.py- Using file:// URLs for local HTMLconsole_logging.py- Capturing console logs during automation





首页
