Playwright 网页应用测试
webapp-testing
使用 Playwright 与本地 Web 应用程序交互并进行测试的工具包。支持验证前端功能、调试 UI 行为、捕获浏览器截图以及查看浏览器日志。
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-15
- Stars
- ★ 19w
- Forks
- 2.3w
01 前言 Front Matter
- name
- webapp-testing
- license
- Complete terms in LICENSE.txt
- description
- Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
02 资源文件 5
- 脚本examples/console_logging.py1.0 KB
- 脚本examples/element_discovery.py1.4 KB
- 脚本examples/static_html_automation.py953 B
- 许可证LICENSE.txt11.1 KB
- 脚本scripts/with_server.py3.6 KB
03 SKILL.md 正文
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 selectors
Example: 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.py
Multiple 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_playwright
with 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
04 同仓库更多 Skills
电子表格文件处理
xlsx
当电子表格文件是主要输入或输出时,使用此技能。这意味着用户想要执行以下任何任务:打开、读取、编辑或修复现有的 .xlsx、.xlsm、.xltx、.csv 或 .tsv 文件(例如添加列、计算公式、格式化、绘制图表、清理杂乱数据);从头开始或从其他数据源创建新的电子表格;或在表格文件格式之间进行转换。当用户按名称或路径引用电子表格文件时应特别触发——即使是随意提及(如“我下载文件夹里的那个 xlsx”)——并希望对其进行处理或从中生成内容。也适用于将杂乱的表格数据文件(格式错误的行、错位的表头、垃圾数据)清理或重组为规范的电子表格。交付成果必须是电子表格文件。即使涉及表格数据,当主要交付成果是 Word 文档、HTML 报告、独立的 Python 脚本、数据库管道或 Google Sheets API 集成时,也不要触发。
React 网页应用构建
web-artifacts-builder
用于创建精细的、多组件的 claude.ai HTML 作品(artifact)的工具套件,采用现代前端 Web 技术(React、Tailwind CSS、shadcn/ui)。适用于需要状态管理、路由或 shadcn/ui 组件的复杂作品,而不适用于简单的单文件 HTML/JSX 作品。
作品主题样式设计
theme-factory
用于为作品(artifact)应用主题样式的工具包。这些作品可以是幻灯片、文档、报告、HTML 落地页等。提供 10 个带颜色/字体的预设主题,可应用于任何已创建的作品,也可即时生成新主题。
Slack 动态 GIF 制作
slack-gif-creator
用于创建针对 Slack 优化的动态 GIF 的知识和实用工具。提供约束条件、验证工具和动画概念。适用于用户请求为 Slack 制作动态 GIF,例如“帮我做一个 X 做 Y 的 Slack GIF”。
技能创建与优化
skill-creator
创建新技能、修改和改进现有技能,并衡量技能性能。适用于用户想要从零开始创建技能、编辑或优化现有技能、运行评估(eval)以测试技能、通过方差分析对技能性能进行基准测试,或优化技能描述以提高触发准确度。
PPT 演示文稿处理
pptx
只要涉及 .pptx 或 .potx 文件(无论是作为输入、输出,还是两者兼有),都应使用此技能。这包括:创建幻灯片组、推介演示文稿或演示文稿;读取、解析或从任何 .pptx 或 .potx 文件中提取文本(即使提取的内容将用于其他地方,例如电子邮件或摘要);编辑、修改或更新现有演示文稿;合并或拆分幻灯片文件;处理模板(.potx)、版式、演讲者备注或批注。每当用户提到“幻灯片组(deck)”“幻灯片(slides)”“演示文稿(presentation)”,或引用 .pptx 或 .potx 文件名时都应触发,无论他们之后打算如何处理这些内容。如果需要打开、创建或处理 .pptx 或 .potx 文件,请使用此技能。