Community编程与开发github.com

webapp-testing

用于通过 Playwright 与本地 Web 应用交互并进行测试的工具包。支持验证前端功能、调试 UI 行为、捕获浏览器截图以及查看浏览器日志。

webapp-testing 是什么?

该技能提供了一套完整的工具和方法,用于自动化测试本地 Web 应用程序,主要基于 Python 和 Playwright。它特别强调了使用辅助脚本来管理应用服务器的生命周期,例如 `scripts/with_server.py` 可以支持单个或多个服务器(如前后端分离应用)的自动启动和销毁。技能中提供了一个清晰的决策树,指导开发者根据应用是否为静态 HTML 来选择测试策略:静态应用可直接读取文件定位元素,动态应用则需要通过服务器管理脚本先启动服务,然后执行 Playwright 脚本进行侦察(截屏、检查 DOM)后再操作。关键实践是始终将 Playwright 脚本与服务器管理逻辑分离,将辅助脚本视为黑盒,通过 `--help` 了解用法后直接调用,以避免不必要的上下文开销。该技能适用于任何需要自动化测试本地 Web 应用的开发场景,尤其在需要处理复杂服务器启动流程时能显著简化工作流。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComposioHQ/awesome-claude-skills/tree/master/webapp-testing

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Web 应用程序测试

要测试本地 Web 应用程序,请编写原生 Python Playwright 脚本。

可用的辅助脚本:

  • scripts/with_server.py - 管理服务器生命周期(支持多个服务器)

始终先运行 --help 查看脚本用法。在尝试运行脚本并发现确实需要自定义解决方案之前,请勿阅读源码。这些脚本可能非常庞大,会污染你的上下文窗口。它们应作为黑盒脚本直接调用,而非被引入到上下文窗口中。

决策树:选择你的方法

用户任务 → 是否为静态 HTML?
    ├─ 是 → 直接读取 HTML 文件以识别选择器
    │         ├─ 成功 → 使用选择器编写 Playwright 脚本
    │         └─ 失败/不完整 → 视为动态应用(如下)
    │
    └─ 否(动态 Web 应用)→ 服务器是否已运行?
        ├─ 否 → 运行:python scripts/with_server.py --help
        │        然后使用辅助脚本 + 编写简化的 Playwright 脚本
        │
        └─ 是 → 先侦察再行动:
            1. 导航并等待 networkidle
            2. 截取屏幕截图或检查 DOM
            3. 根据渲染状态识别选择器
            4. 使用发现的选择器执行操作

示例:使用 with_server.py

要启动服务器,请先运行 --help,然后使用辅助脚本:

单个服务器:

python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.py

多个服务器(例如,后端 + 前端):

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 逻辑(服务器由管理脚本自动管理):

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:

    page.screenshot(path='/tmp/inspect.png', full_page=True)
    content = page.content()
    page.locator('button').all()
    
  2. 从检查结果中识别选择器

  3. 使用发现的选择器执行操作

常见陷阱

❌ 不要在等待动态应用的 networkidle 之前检查 DOM ✅ 应该在检查之前等待 page.wait_for_load_state('networkidle')

最佳实践

  • 将捆绑脚本作为黑盒使用 - 要完成某项任务,请考虑 scripts/ 中的脚本是否能提供帮助。这些脚本能够可靠地处理常见且复杂的工作流程,同时不会占用你的上下文窗口。使用 --help 查看用法,然后直接调用。
  • 使用 sync_playwright() 来编写同步脚本
  • 完成后始终关闭浏览器
  • 使用描述性选择器:text=、role=、CSS 选择器或 ID
  • 添加适当的等待:page.wait_for_selector() 或 page.wait_for_timeout()

参考文件

  • examples/ - 展示常见模式的示例:
    • element_discovery.py - 在页面上发现按钮、链接和输入框
    • static_html_automation.py - 对本地 HTML 使用 file:// URL
    • console_logging.py - 在自动化期间捕获控制台日志

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ably-automation

Automate Ably tasks via Rube MCP (Composio). Always search tools first for current schemas.

abstract-automation

Automate Abstract tasks via Rube MCP (Composio). Always search tools first for current schemas.

abuselpdb-automation

Automate Abuselpdb tasks via Rube MCP (Composio). Always search tools first for current schemas.

abyssale-automation

Automate Abyssale tasks via Rube MCP (Composio). Always search tools first for current schemas.

accelo-automation

Automate Accelo tasks via Rube MCP (Composio). Always search tools first for current schemas.

accredible-certificates-automation

Automate Accredible Certificates tasks via Rube MCP (Composio). Always search tools first for current schemas.

acculynx-automation

Automate Acculynx tasks via Rube MCP (Composio). Always search tools first for current schemas.

active-campaign-automation

Automate ActiveCampaign tasks via Rube MCP (Composio). Always search tools first for current schemas.

addresszen-automation

Automate Addresszen tasks via Rube MCP (Composio). Always search tools first for current schemas.

adobe-automation

Automate Adobe tasks via Rube MCP (Composio). Always search tools first for current schemas.

adrapid-automation

Automate Adrapid tasks via Rube MCP (Composio). Always search tools first for current schemas.

adyntel-automation

Automate Adyntel tasks via Rube MCP (Composio). Always search tools first for current schemas.

aeroleads-automation

Automate Aeroleads tasks via Rube MCP (Composio). Always search tools first for current schemas.

aero-workflow-automation

Automate Aero Workflow tasks via Rube MCP (Composio). Always search tools first for current schemas.

affinda-automation

Automate Affinda tasks via Rube MCP (Composio). Always search tools first for current schemas.

affinity-automation

Automate Affinity tasks via Rube MCP (Composio). Always search tools first for current schemas.

agencyzoom-automation

Automate Agencyzoom tasks via Rube MCP (Composio). Always search tools first for current schemas.

agent-mail-automation

Automate Agent Mail tasks via Rube MCP (Composio). Always search tools first for current schemas.

agentql-automation

Automate Agentql tasks via Rube MCP (Composio). Always search tools first for current schemas.

agenty-automation

Automate Agenty tasks via Rube MCP (Composio). Always search tools first for current schemas.

相关技能