← ClaudeAtlas

webapp-testinglisted

用于使用 Playwright 与本地 Web 应用交互和测试的工具包。支持验证前端功能、调试 UI 行为、捕获浏览器屏幕截图以及查看浏览器日志。
Fantasia1999/skills-zh · ★ 0 · Testing & QA · score 55
Install: claude install-skill Fantasia1999/skills-zh
# Web 应用测试 要测试本地 Web 应用,请编写原生的 Python Playwright 脚本。 **可用的辅助脚本**: - `scripts/with_server.py` - 管理服务器生命周期(支持多个服务器) **务必先使用 `--help` 运行脚本**来查看用法。在尝试运行脚本并发现确实需要定制化解决方案之前,不要阅读源代码。这些脚本可能非常大,会污染您的上下文窗口。它们的存在是为了作为黑盒脚本直接调用,而不是被加载到您的上下文窗口中。 ## 决策树:选择您的方法 ``` 用户任务 → 是静态 HTML 吗? ├─ 是 → 直接读取 HTML 文件以识别选择器 │ ├─ 成功 → 使用选择器编写 Playwright 脚本 │ └─ 失败/不完整 �� 按动态应用处理(见下文) │ └─ 否(动态 webapp)→ 服务器是否已在运行? ├─ 否 → 运行:python scripts/with_server.py --help │ 然后使用该辅助脚本 + 编写简化的 Playwright 脚本 │ └─ 是 → 侦察-然后-行动: 1. 导航并等待 networkidle 2. 截屏或检查 DOM 3. 从渲染状态中识别选择器 4. 使用发现的选择器执行操作 ``` ## 示例:使用 with_server.py 要启动服务器,请先运行 `--help`,然后使用该辅助脚本: **单个服务器:** ```bash python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.py ``` **多个服务器(例如,后端 + 前端):** ```bash 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 ``` 要创建自动化脚本,只需包含 Playwright 逻辑(服务器会自动管理): ```python from playwright.sync_api import sync_playwright with sync_playwright() as p: browser = p.chromium.launch(headless=True) # 始终以无头模式启动 chromium page = browser.new_page() page.goto('http://localhost:5173') # 服务器已运行并就绪 page.wait_for_load_state('networkidle') # 关键:等待 JS 执行 # ... 你的自动化逻辑 browser.close() ``` ## 侦察-然后-行动 模式 1. **检查渲染后的 DOM**: ```python pa