| name | clawfirm-test |
| description | Testing and automating the Clawfirm desktop app UI using the browser-agent CLI (NOT agent-browser). ⚠️ browser-agent ≠ agent-browser — they are different binaries: browser-agent talks to Clawfirm's WKWebView eval server; agent-browser uses Chrome/CDP for external websites. Use THIS skill (browser-agent) whenever the user wants to: test a Clawfirm feature, automate the Clawfirm UI, send messages in Clawfirm, test '打开新对话', run dual-instance tests (Primary drives Secondary), or control Clawfirm's WKWebView. Trigger on: 'test the app', '帮我测试', 'UI test', 'browser-agent', 'clawfirm-test', or any request involving Clawfirm app automation. |
Clawfirm UI Testing with browser-agent
⚠️ browser-agent ≠ agent-browser
browser-agent → Clawfirm WKWebView,通过 eval server(port 9310/9311)注入 JS,本 skill 使用此工具
agent-browser → Chrome/Chromium via CDP,用于外部网站自动化,不适用于 Clawfirm
环境检查
运行任何测试前,先确认环境:
which browser-agent || go install ./cmd/browser-agent/
curl -s --noproxy localhost -X POST http://localhost:9310/api/eval \
-H 'Content-Type: application/json' \
-d '{"script":"document.title"}' | python3 -m json.tool
若 app 未运行,用 testserver 代替(指向任意 URL):
go run ./cmd/browser-agent/testserver/ http://localhost:9988
go run ./cmd/browser-agent/testserver/ https://example.com
核心工作流
始终先 snapshot 获取 refs,再操作。
browser-agent snapshot -i
browser-agent click @e3
browser-agent fill @e2 "hello world"
browser-agent press Enter
browser-agent snapshot -i
Ref 生命周期:每次 snapshot 会重置 refs。导航或页面变化后必须重新 snapshot。
命令速查
Snapshot(元素分析)
browser-agent snapshot -i
browser-agent snapshot
browser-agent snapshot -c
browser-agent snapshot -d 3
browser-agent snapshot -s "#main"
交互(用 snapshot 拿到的 @ref)
browser-agent click @e1
browser-agent dblclick @e1
browser-agent fill @e2 "text"
browser-agent type @e2 "text"
browser-agent press Enter
browser-agent hover @e1
browser-agent check @e1
browser-agent uncheck @e1
browser-agent select @e1 "option"
browser-agent scroll down 500
browser-agent scrollintoview @e1
获取信息
browser-agent get text @e1
browser-agent get html @e1
browser-agent get value @e1
browser-agent get attr @e1 href
browser-agent get title
browser-agent get url
状态检查
browser-agent is visible @e1
browser-agent is enabled @e1
browser-agent is checked @e1
等待
browser-agent wait 2000
browser-agent wait @e1
browser-agent wait --text "成功"
browser-agent wait --url "/chat"
语义定位(不用 ref)
browser-agent find text "发送" click
browser-agent find role button click
browser-agent find label "消息输入" fill "你好"
browser-agent find placeholder "输入消息" click
browser-agent find testid "send-btn" click
JavaScript
browser-agent eval "document.title"
browser-agent eval -b "$(echo 'document.querySelectorAll("button").length' | base64)"
Clawfirm 常见测试场景
发送消息
browser-agent snapshot -i
browser-agent fill @e6 "你好,请介绍一下自己"
browser-agent find text "Send" click
browser-agent wait --text "Stop" --timeout 15000
browser-agent wait --text "Send" --timeout 30000
browser-agent eval "
(function(){
var msgs = document.querySelectorAll('.flex.justify-start');
return msgs.length ? msgs[msgs.length-1].textContent.trim().slice(0,200) : 'no reply';
})()"
停止生成
browser-agent find text "Stop" click
打开新对话
browser-agent find text "+ New Chat" click
browser-agent snapshot -i
browser-agent click @eN
browser-agent fill @eN "/new"
browser-agent find text "Send" click
browser-agent wait --text "Start a conversation" --timeout 10000
browser-agent eval "document.querySelector('header button[title=\"Copy thread ID\"]')?.textContent"
切换 Agent
browser-agent snapshot -i
browser-agent click @e_agent
browser-agent wait --text "Start a conversation"
验证工具调用
browser-agent wait --text "done"
browser-agent snapshot -s "#tool-panel"
写 Shell 脚本测试
可以把场景写成 shell 脚本,方便复用:
#!/bin/bash
set -e
echo "=== 测试:发送消息并等待回复 ==="
browser-agent snapshot -i
browser-agent fill @e2 "1+1等于几"
browser-agent press Enter
browser-agent wait --text "2" --timeout 30000
echo "✓ 回复正常"
browser-agent get url
输出格式说明
Snapshot 输出格式(与 agent-browser 一致):
Page: Clawfirm
URL: http://localhost:9988
- heading "Clawfirm" [level=1, ref=e1]
- textbox "输入消息" [ref=e2]
- button "发送" [ref=e3]
- button "Stop" [disabled, ref=e4]
[ref=eN] — 用于后续命令的引用
[disabled] — 不可用状态
[checked=true/false] — checkbox 状态
[expanded=true/false] — 展开状态
: value — input 的当前值
注意事项
双实例测试环境(Primary → Secondary)
用第一个 Clawfirm(Primary,端口 9310)的 agent 驱动第二个 Clawfirm(Secondary,端口 9311),两者 workspace 完全隔离。
启动 Secondary 实例
CLAWFIRM_DATA_DIR=~/.clawfirm-test \
CLAWFIRM_EVAL_PORT=9311 \
CLAWFIRM_LOG_PATH=~/.clawfirm-test/app.log \
http_proxy= https_proxy= HTTP_PROXY= HTTPS_PROXY= all_proxy= ALL_PROXY= \
/Applications/clawfirm.app/Contents/MacOS/clawfirm &
sleep 8
curl -s --noproxy localhost -X POST http://localhost:9311/api/eval \
-H 'Content-Type: application/json' \
-d '{"script":"document.title"}'
Secondary 的数据(DB、config、logs)全部在 ~/.clawfirm-test/,不会和 Primary 的 ~/.clawfirm/ 冲突。
Primary 读取 Secondary 的日志(debug)
Secondary 启动时传入 CLAWFIRM_LOG_PATH,Primary agent 可以直接读取:
cat ~/.clawfirm-test/app.log | tail -80
grep -i "error\|panic\|fatal" ~/.clawfirm-test/app.log | tail -20
grep -E "agent:|tool:|provider:" ~/.clawfirm-test/app.log | tail -30
典型 debug 流程:
- 向 Secondary 发送测试消息后,如果没有回复或行为异常
cat ~/.clawfirm-test/app.log | tail -80 读取最近日志
- 分析错误原因(provider 超时、tool 执行失败、JS eval 错误等)
- 根据日志调整测试策略或报告问题
CLAWFIRM_LOG_PATH 支持 ~/ 前缀展开,也可以指定任意绝对路径(如 /tmp/secondary.log)。
Primary agent 中使用 browser-agent 控制 Secondary
BROWSER_AGENT_PORT=9311 browser-agent snapshot -i
BROWSER_AGENT_PORT=9311 browser-agent find text "Send" click
或者在测试脚本中 export:
#!/bin/bash
export BROWSER_AGENT_PORT=9311
browser-agent snapshot -i
browser-agent fill @e2 "你好"
browser-agent find text "Send" click
browser-agent wait --text "Stop" --timeout 15000
browser-agent wait --text "Send" --timeout 30000
echo "✓ Secondary 回复正常"
确认 Secondary eval server 在线
curl -s --noproxy localhost -X POST http://localhost:9311/api/eval \
-H 'Content-Type: application/json' \
-d '{"script":"document.title"}' | python3 -m json.tool