ce-test-browser
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBrowser Test Skill
浏览器测试技能
Run end-to-end browser tests on pages affected by a PR or branch changes using the CLI.
agent-browser使用 CLI针对PR或分支变更影响的页面运行端到端浏览器测试。
agent-browserUse agent-browser
Only For Browser Automation
agent-browser仅使用agent-browser
进行浏览器自动化
agent-browserThis workflow uses the CLI exclusively. Do not use any alternative browser automation system, browser MCP integration, or built-in browser-control tool. If the platform offers multiple ways to control a browser, always choose .
agent-browseragent-browserUse for: opening pages, clicking elements, filling forms, taking screenshots, and scraping rendered content.
agent-browserPlatform-specific hints:
- In Claude Code, do not use Chrome MCP tools ().
mcp__claude-in-chrome__* - In Codex, do not substitute unrelated browsing tools.
此工作流仅使用 CLI。请勿使用任何替代浏览器自动化系统、浏览器MCP集成或内置浏览器控制工具。如果平台提供多种控制浏览器的方式,请始终选择。
agent-browseragent-browser使用完成以下操作:打开页面、点击元素、填写表单、截取屏幕截图以及抓取渲染内容。
agent-browser平台特定提示:
- 在Claude Code中,请勿使用Chrome MCP工具()。
mcp__claude-in-chrome__* - 在Codex中,请勿替换为无关的浏览工具。
Prerequisites
前提条件
- Local development server running (e.g., ,
bin/dev,rails server)npm run dev - CLI installed (see Setup below)
agent-browser - Git repository with changes to test
- 本地开发服务器正在运行(例如:、
bin/dev、rails server)npm run dev - 已安装CLI(请参阅下方设置步骤)
agent-browser - 包含待测试变更的Git仓库
Setup
设置
Check whether is installed:
agent-browserbash
command -v agent-browser >/dev/null 2>&1 && echo "Installed" || echo "NOT INSTALLED"If not installed, inform the user: " is not installed. Run to install required dependencies." Then stop — this skill cannot function without agent-browser.
agent-browser/ce-setup检查是否已安装:
agent-browserbash
command -v agent-browser >/dev/null 2>&1 && echo "Installed" || echo "NOT INSTALLED"如果未安装,请告知用户:"未安装。运行以安装所需依赖。" 然后停止操作——没有agent-browser,此技能无法运行。
agent-browser/ce-setupWorkflow
工作流
1. Verify Installation
1. 验证安装
Before starting, verify is available:
agent-browserbash
command -v agent-browser >/dev/null 2>&1 && echo "Ready" || echo "NOT INSTALLED"If not installed, inform the user: " is not installed. Run to install required dependencies." Then stop.
agent-browser/ce-setup开始前,验证是否可用:
agent-browserbash
command -v agent-browser >/dev/null 2>&1 && echo "Ready" || echo "NOT INSTALLED"如果未安装,请告知用户:"未安装。运行以安装所需依赖。" 然后停止操作。
agent-browser/ce-setup2. Ask Browser Mode
2. 询问浏览器模式
Ask the user whether to run headed or headless using the platform's blocking question tool: in Claude Code (call with first if its schema isn't loaded), in Codex, in Gemini, in Pi (requires the extension). Fall back to presenting options in chat only when no blocking tool exists in the harness or the call errors (e.g., Codex edit modes) — not because a schema load is required. Never silently skip the question:
AskUserQuestionToolSearchselect:AskUserQuestionrequest_user_inputask_userask_userpi-ask-userDo you want to watch the browser tests run?
1. Headed (watch) - Opens visible browser window so you can see tests run
2. Headless (faster) - Runs in background, faster but invisibleStore the choice and use the flag when the user selects option 1.
--headed使用平台的阻塞式提问工具询问用户是运行有头模式还是无头模式:Claude Code中使用(如果未加载其架构,先调用并指定),Codex中使用,Gemini中使用,Pi中使用(需要扩展)。仅当工具集中没有阻塞式工具或调用出错时(例如Codex编辑模式),才回退到在聊天中展示选项——不要因为需要加载架构而跳过。切勿静默跳过此问题:
AskUserQuestionToolSearchselect:AskUserQuestionrequest_user_inputask_userask_userpi-ask-user您是否想要查看浏览器测试的运行过程?
1. 有头模式(可查看)- 打开可见的浏览器窗口,以便您查看测试运行
2. 无头模式(更快)- 在后台运行,速度更快但不可见保存用户的选择,当用户选择选项1时,使用标志。
--headed3. Determine Test Scope
3. 确定测试范围
If PR number provided:
bash
gh pr view [number] --json files -q '.files[].path'If 'current' or empty:
bash
git diff --name-only main...HEADIf branch name provided:
bash
git diff --name-only main...[branch]如果提供了PR编号:
bash
gh pr view [number] --json files -q '.files[].path'如果是'current'或为空:
bash
git diff --name-only main...HEAD如果提供了分支名称:
bash
git diff --name-only main...[branch]4. Map Files to Routes
4. 将文件映射到路由
Map changed files to testable routes:
| File Pattern | Route(s) |
|---|---|
| |
| |
| Pages using that Stimulus controller |
| Pages rendering that component |
| All pages (test homepage at minimum) |
| Visual regression on key pages |
| Pages using that helper |
| Corresponding routes |
| Pages using those components |
Build a list of URLs to test based on the mapping.
将变更文件映射到可测试的路由:
| 文件模式 | 路由 |
|---|---|
| |
| |
| 使用该Stimulus控制器的页面 |
| 渲染该组件的页面 |
| 所有页面(至少测试首页) |
| 关键页面的视觉回归测试 |
| 使用该助手的页面 |
| 对应的路由 |
| 使用这些组件的页面 |
根据映射构建待测试的URL列表。
5. Detect Dev Server Port
5. 检测开发服务器端口
Determine the dev server port using this priority:
- Explicit argument — if the user passed , use that directly
--port 5000 - Project instructions — check ,
AGENTS.md, or other instruction files for port referencesCLAUDE.md - package.json — check dev/start scripts for flags
--port - Environment files — check ,
.env,.env.localfor.env.developmentPORT= - Default — fall back to
3000
bash
PORT="${EXPLICIT_PORT:-}"
if [ -z "$PORT" ]; then
PORT=$(grep -Eio '(port\s*[:=]\s*|localhost:)([0-9]{4,5})' AGENTS.md 2>/dev/null | grep -Eo '[0-9]{4,5}' | head -1)
if [ -z "$PORT" ]; then
PORT=$(grep -Eio '(port\s*[:=]\s*|localhost:)([0-9]{4,5})' CLAUDE.md 2>/dev/null | grep -Eo '[0-9]{4,5}' | head -1)
fi
fi
if [ -z "$PORT" ]; then
PORT=$(grep -Eo '\-\-port[= ]+[0-9]{4,5}' package.json 2>/dev/null | grep -Eo '[0-9]{4,5}' | head -1)
fi
if [ -z "$PORT" ]; then
PORT=$(grep -h '^PORT=' .env .env.local .env.development 2>/dev/null | tail -1 | cut -d= -f2)
fi
PORT="${PORT:-3000}"
echo "Using dev server port: $PORT"按照以下优先级确定开发服务器端口:
- 显式参数 — 如果用户传入,直接使用该端口
--port 5000 - 项目说明 — 检查、
AGENTS.md或其他说明文件中的端口引用CLAUDE.md - package.json — 检查dev/start脚本中的标志
--port - 环境文件 — 检查、
.env、.env.local中的.env.development配置PORT= - 默认值 — 回退到
3000
bash
PORT="${EXPLICIT_PORT:-}"
if [ -z "$PORT" ]; then
PORT=$(grep -Eio '(port\s*[:=]\s*|localhost:)([0-9]{4,5})' AGENTS.md 2>/dev/null | grep -Eo '[0-9]{4,5}' | head -1)
if [ -z "$PORT" ]; then
PORT=$(grep -Eio '(port\s*[:=]\s*|localhost:)([0-9]{4,5})' CLAUDE.md 2>/dev/null | grep -Eo '[0-9]{4,5}' | head -1)
fi
fi
if [ -z "$PORT" ]; then
PORT=$(grep -Eo '\-\-port[= ]+[0-9]{4,5}' package.json 2>/dev/null | grep -Eo '[0-9]{4,5}' | head -1)
fi
if [ -z "$PORT" ]; then
PORT=$(grep -h '^PORT=' .env .env.local .env.development 2>/dev/null | tail -1 | cut -d= -f2)
fi
PORT="${PORT:-3000}"
echo "Using dev server port: $PORT"6. Verify Server is Running
6. 验证服务器是否运行
bash
agent-browser open http://localhost:${PORT}
agent-browser snapshot -iIf the server is not running, inform the user:
Server not running on port ${PORT}
Please start your development server:
- Rails: `bin/dev` or `rails server`
- Node/Next.js: `npm run dev`
- Custom port: run this skill again with `--port <your-port>`
Then re-run this skill.bash
agent-browser open http://localhost:${PORT}
agent-browser snapshot -i如果服务器未运行,请告知用户:
服务器未在端口${PORT}运行
请启动您的开发服务器:
- Rails: `bin/dev` 或 `rails server`
- Node/Next.js: `npm run dev`
- 自定义端口:重新运行此技能并添加`--port <your-port>`参数
然后重新运行此技能。7. Test Each Affected Page
7. 测试每个受影响的页面
For each affected route:
Navigate and capture snapshot:
bash
agent-browser open "http://localhost:${PORT}/[route]"
agent-browser snapshot -iFor headed mode:
bash
agent-browser --headed open "http://localhost:${PORT}/[route]"
agent-browser --headed snapshot -iVerify key elements:
- Use to get interactive elements with refs
agent-browser snapshot -i - Page title/heading present
- Primary content rendered
- No error messages visible
- Forms have expected fields
Test critical interactions:
bash
agent-browser click @e1
agent-browser snapshot -iTake screenshots:
bash
agent-browser screenshot page-name.png
agent-browser screenshot --full page-name-full.png针对每个受影响的路由:
导航并捕获快照:
bash
agent-browser open "http://localhost:${PORT}/[route]"
agent-browser snapshot -i有头模式下:
bash
agent-browser --headed open "http://localhost:${PORT}/[route]"
agent-browser --headed snapshot -i验证关键元素:
- 使用获取带引用的交互元素
agent-browser snapshot -i - 页面标题/标题存在
- 主要内容已渲染
- 无可见错误消息
- 表单包含预期字段
测试关键交互:
bash
agent-browser click @e1
agent-browser snapshot -i截取屏幕截图:
bash
agent-browser screenshot page-name.png
agent-browser screenshot --full page-name-full.png8. Human Verification (When Required)
8. 人工验证(必要时)
Pause for human input when testing touches flows that require external interaction:
| Flow Type | What to Ask |
|---|---|
| OAuth | "Please sign in with [provider] and confirm it works" |
| "Check your inbox for the test email and confirm receipt" | |
| Payments | "Complete a test purchase in sandbox mode" |
| SMS | "Verify you received the SMS code" |
| External APIs | "Confirm the [service] integration is working" |
Ask the user (using the platform's question tool, or present numbered options and wait):
Human Verification Needed
This test touches [flow type]. Please:
1. [Action to take]
2. [What to verify]
Did it work correctly?
1. Yes - continue testing
2. No - describe the issue当测试涉及需要外部交互的流程时,暂停以等待人工输入:
| 流程类型 | 询问内容 |
|---|---|
| OAuth | "请使用[提供商]登录并确认功能正常" |
| 邮件 | "检查您的收件箱以获取测试邮件并确认已收到" |
| 支付 | "在沙箱模式下完成测试购买" |
| SMS | "验证您已收到SMS验证码" |
| 外部API | "确认[服务]集成正常工作" |
询问用户(使用平台的提问工具,或展示编号选项并等待):
需要人工验证
此测试涉及[流程类型]。请:
1. [执行操作]
2. [验证内容]
是否正常工作?
1. 是 - 继续测试
2. 否 - 描述问题9. Handle Failures
9. 处理失败
When a test fails:
-
Document the failure:
- Screenshot the error state:
agent-browser screenshot error.png - Note the exact reproduction steps
- Screenshot the error state:
-
Ask the user how to proceed:
Test Failed: [route] Issue: [description] Console errors: [if any] How to proceed? 1. Fix now - debug and fix the failing test 2. Skip - continue testing other pages -
If "Fix now": investigate, propose a fix, apply, re-run the failing test
-
If "Skip": log as skipped, continue
当测试失败时:
-
记录失败情况:
- 截取错误状态的屏幕截图:
agent-browser screenshot error.png - 记录确切的重现步骤
- 截取错误状态的屏幕截图:
-
询问用户如何继续:
测试失败:[route] 问题:[描述] 控制台错误:[如有] 如何继续? 1. 立即修复 - 调试并修复失败的测试 2. 跳过 - 继续测试其他页面 -
如果选择"立即修复": 调查问题,提出修复方案,应用修复,重新运行失败的测试
-
如果选择"跳过": 记录为已跳过,继续测试
10. Test Summary
10. 测试总结
After all tests complete, present a summary:
markdown
undefined所有测试完成后,呈现总结:
markdown
undefinedBrowser Test Results
浏览器测试结果
Test Scope: PR #[number] / [branch name]
Server: http://localhost:${PORT}
测试范围: PR #[number] / [分支名称]
服务器: http://localhost:${PORT}
Pages Tested: [count]
已测试页面:[数量]
| Route | Status | Notes |
|---|---|---|
| Pass | |
| Pass | |
| Fail | Console error: [msg] |
| Skip | Requires payment credentials |
| 路由 | 状态 | 备注 |
|---|---|---|
| 通过 | |
| 通过 | |
| 失败 | 控制台错误:[消息] |
| 跳过 | 需要支付凭证 |
Console Errors: [count]
控制台错误:[数量]
- [List any errors found]
- [列出所有发现的错误]
Human Verifications: [count]
人工验证:[数量]
- OAuth flow: Confirmed
- Email delivery: Confirmed
- OAuth流程:已确认
- 邮件投递:已确认
Failures: [count]
失败项:[数量]
- - [issue description]
/dashboard
- - [问题描述]
/dashboard
Result: [PASS / FAIL / PARTIAL]
结果:[通过 / 失败 / 部分通过]
undefinedundefinedQuick Usage Examples
快速使用示例
bash
undefinedbash
undefinedTest current branch changes (auto-detects port)
测试当前分支的变更(自动检测端口)
/ce-test-browser
/ce-test-browser
Test specific PR
测试特定PR
/ce-test-browser 847
/ce-test-browser 847
Test specific branch
测试特定分支
/ce-test-browser feature/new-dashboard
/ce-test-browser feature/new-dashboard
Test on a specific port
在特定端口上测试
/ce-test-browser --port 5000
undefined/ce-test-browser --port 5000
undefinedagent-browser CLI Reference
agent-browser CLI参考
Run for all commands.
agent-browser --helpKey commands:
bash
undefined运行查看所有命令。
agent-browser --help关键命令:
bash
undefinedNavigation
导航
agent-browser open <url> # Navigate to URL
agent-browser back # Go back
agent-browser close # Close browser
agent-browser open <url> # 导航到URL
agent-browser back # 返回上一页
agent-browser close # 关闭浏览器
Snapshots (get element refs)
快照(获取元素引用)
agent-browser snapshot -i # Interactive elements with refs (@e1, @e2, etc.)
agent-browser snapshot -i --json # JSON output
agent-browser snapshot -i # 带引用的交互元素(@e1、@e2等)
agent-browser snapshot -i --json # JSON格式输出
Interactions (use refs from snapshot)
交互(使用快照中的引用)
agent-browser click @e1 # Click element
agent-browser fill @e1 "text" # Fill input
agent-browser type @e1 "text" # Type without clearing
agent-browser press Enter # Press key
agent-browser click @e1 # 点击元素
agent-browser fill @e1 "text" # 填充输入框
agent-browser type @e1 "text" # 输入文本(不清空原有内容)
agent-browser press Enter # 按下回车键
Screenshots
屏幕截图
agent-browser screenshot out.png # Viewport screenshot
agent-browser screenshot --full out.png # Full page screenshot
agent-browser screenshot out.png # 视口截图
agent-browser screenshot --full out.png # 全页截图
Headed mode (visible browser)
有头模式(可见浏览器)
agent-browser --headed open <url> # Open with visible browser
agent-browser --headed click @e1 # Click in visible browser
agent-browser --headed open <url> # 在可见浏览器中打开
agent-browser --headed click @e1 # 在可见浏览器中点击
Wait
等待
agent-browser wait @e1 # Wait for element
agent-browser wait 2000 # Wait milliseconds
undefinedagent-browser wait @e1 # 等待元素出现
agent-browser wait 2000 # 等待毫秒数
undefined