Community程式設計與開發github.com

網頁應用程式測試

使用 Playwright 與本機網頁應用程式互動並進行測試的工具包。支援驗證前端功能、除錯 UI 行為、擷取瀏覽器螢幕截圖及檢視瀏覽器日誌。

網頁應用程式測試 是什麼?

這個技能提供了一個結構化的方法,用於使用 Playwright 測試本機網頁應用程式,特別適用於 AI 代理(如 Claude Code、Cursor、Codex)。它透過一套輔助腳本(最著名的是 `with_server.py`)來管理伺服器生命週期,讓代理可以專注於編寫 Playwright 自動化邏輯,而無需擔心伺服器設定。此技能引入了一個「偵查-行動」模式,首先透過導航至動態頁面、等待 `networkidle` 狀態,並在與元素互動前檢查渲染後的 DOM 來收集情報。它引導使用者區分靜態 HTML(可以直接從原始檔案讀取選擇器)與動態網頁應用程式(需要伺服器處理與執行階段渲染)。該技能支援單一或多部伺服器(例如後端 API + 前端 UI)的設定,並為擷取螢幕截圖、擷取內容及執行帶有其他 Playwright 標準做法(如 `sync_playwright()`、選擇器策略與資源清理)的操作提供明確的 Playwright 範例。

相容平台~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 的新對話。

說明文件

網頁應用程式測試 是做什麼的?

若要測試本機網頁應用程式,請撰寫原生 Python Playwright 指令碼。

可用的輔助指令碼:

  • scripts/with_server.py - 管理伺服器生命週期(支援多部伺服器)

請務必先使用 --help 執行指令碼 以了解用法。請勿閱讀原始碼,除非您先嘗試執行指令碼後,發現確實需要自訂解決方案。這些指令碼可能非常龐大,因而會污染您的提示上下文。它們是作為黑箱指令碼直接呼叫使用,而非匯入到您的提示上下文中。

決策樹:選擇您的方法

使用者任務 → 是否為靜態 HTML?
    ├─ 是 → 直接讀取 HTML 檔案以識別選擇器
    │         ├─ 成功 → 使用選擇器撰寫 Playwright 指令碼
    │         └─ 失敗/不完整 → 視為動態網頁(如下所示)
    │
    └─ 否(動態網頁應用程式) → 伺服器是否已在執行中?
        ├─ 否 → 執行: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') # 關鍵:等待 JavaScript 執行
    # ... 您的自動化邏輯
    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 - 使用 file:// URL 處理本機 HTML
    • 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.

相關技能