自动化测试 · 技能模板

WebAppTestingSkill

参考官方 webapp-testing 示例,结合 Playwright 与 `with_server.py` 脚本,快速完成本地或多服务前端应用的验证、截图与日志采集。

侦察→执行流程

  • 判断页面类型(静态 HTML 或动态应用)。
  • 运行 `page.wait_for_load_state('networkidle')` 后再截屏或抓取 DOM。
  • 根据侦察结果选取稳定的 role、text 或 CSS 选择器执行操作。

脚本目录

  1. scripts/with_server.py —— 管理单个或多个服务的生命周期。
  2. examples/element_discovery.py —— 枚举页面交互元素。
  3. examples/console_logging.py —— 捕获浏览器控制台输出。
  4. examples/static_html_automation.py —— 静态页面自动化范例。

SKILL.md 提示摘要

---
name: webapp-testing
description: Toolkit for interacting with and testing local web applications using Playwright.
helper_scripts:
  - scripts/with_server.py # 先运行 --help 再调用
best_practices:
  - Treat helper scripts as black boxes
  - Always wait for networkidle
  - Prefer descriptive selectors
  - Close browser when finished

命令示例

python scripts/with_server.py --help
python scripts/with_server.py \
  --server "npm run dev" --port 5173 \
  -- python tests/smoke.py

`smoke.py` 示例可借鉴 examples/element_discovery.py,先列出按钮与输入框,再执行点击或输入动作。若需回归测试,可在 Skill 中补充 Playwright Test runner 的断言示例,并将截图保存至 `/tmp` 提供下载。