gz-laya-pilot 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +20 -2
- package/README.md +54 -2
- package/dist/agent/bridge.d.ts +21 -0
- package/dist/agent/bridge.js +158 -0
- package/dist/agent/bridge.js.map +1 -0
- package/dist/agent/report.d.ts +54 -0
- package/dist/agent/report.js +100 -0
- package/dist/agent/report.js.map +1 -0
- package/dist/agent/run.d.ts +19 -0
- package/dist/agent/run.js +121 -0
- package/dist/agent/run.js.map +1 -0
- package/dist/agent/schema.d.ts +42 -0
- package/dist/agent/schema.js +9 -0
- package/dist/agent/schema.js.map +1 -0
- package/dist/agent/worker.d.ts +1 -0
- package/dist/agent/worker.js +102 -0
- package/dist/agent/worker.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +7 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +14 -6
- package/src/agent/bridge.ts +180 -0
- package/src/agent/report.ts +139 -0
- package/src/agent/run.ts +136 -0
- package/src/agent/schema.ts +38 -0
- package/src/agent/worker.ts +114 -0
- package/src/cli.ts +5 -0
- package/src/index.ts +3 -0
- package/vendor/.gitattributes +5 -0
- package/vendor/UPSTREAM.json +168 -0
- package/vendor/laya-pilot/LICENSE +21 -0
- package/vendor/laya-pilot/README.en.md +116 -0
- package/vendor/laya-pilot/README.md +116 -0
- package/vendor/laya-pilot/ROADMAP.md +21 -0
- package/vendor/laya-pilot/config.example.json +14 -0
- package/vendor/laya-pilot/docs/architecture.md +21 -0
- package/vendor/laya-pilot/docs/browser-use-evaluation.md +32 -0
- package/vendor/laya-pilot/docs/demo.png +0 -0
- package/vendor/laya-pilot/docs/local-runtime.md +88 -0
- package/vendor/laya-pilot/docs/pr1-selection.md +33 -0
- package/vendor/laya-pilot/docs/retry-policy.md +14 -0
- package/vendor/laya-pilot/examples/demo-cases.xlsx +0 -0
- package/vendor/laya-pilot/examples/demo-server.mjs +19 -0
- package/vendor/laya-pilot/examples/demo.html +733 -0
- package/vendor/laya-pilot/lib/auth-state.mjs +141 -0
- package/vendor/laya-pilot/lib/browser-provider.mjs +43 -0
- package/vendor/laya-pilot/lib/diagnostics.mjs +210 -0
- package/vendor/laya-pilot/lib/discovery.mjs +474 -0
- package/vendor/laya-pilot/lib/dom.mjs +539 -0
- package/vendor/laya-pilot/lib/engine.mjs +879 -0
- package/vendor/laya-pilot/lib/form.mjs +377 -0
- package/vendor/laya-pilot/lib/language.mjs +273 -0
- package/vendor/laya-pilot/lib/model.mjs +271 -0
- package/vendor/laya-pilot/lib/page-capabilities.mjs +356 -0
- package/vendor/laya-pilot/lib/page-exploration.mjs +372 -0
- package/vendor/laya-pilot/lib/page-session.mjs +69 -0
- package/vendor/laya-pilot/lib/pending-writes.mjs +50 -0
- package/vendor/laya-pilot/lib/planner.mjs +127 -0
- package/vendor/laya-pilot/lib/project-config.mjs +95 -0
- package/vendor/laya-pilot/lib/readiness.mjs +179 -0
- package/vendor/laya-pilot/lib/related-records.mjs +328 -0
- package/vendor/laya-pilot/lib/replay-model.mjs +44 -0
- package/vendor/laya-pilot/lib/run-state.mjs +133 -0
- package/vendor/laya-pilot/lib/test-data.mjs +128 -0
- package/vendor/laya-pilot/lib/workflow-policy.mjs +68 -0
- package/vendor/laya-pilot/lib/workflow.mjs +2321 -0
- package/vendor/laya-pilot/lib/workflow_excel.py +462 -0
- package/vendor/laya-pilot/requirements-local.txt +2 -0
- package/vendor/laya-pilot/requirements.txt +1 -0
- package/vendor/laya-pilot/runner.mjs +452 -0
- package/vendor/laya-pilot/tests/api.test.mjs +98 -0
- package/vendor/laya-pilot/tests/browser/runtime.test.mjs +847 -0
- package/vendor/laya-pilot/tests/config.test.mjs +109 -0
- package/vendor/laya-pilot/tests/diagnostics.test.mjs +91 -0
- package/vendor/laya-pilot/tests/discovery.test.mjs +76 -0
- package/vendor/laya-pilot/tests/fixtures/local-model/laya.py +28 -0
- package/vendor/laya-pilot/tests/fixtures/local-model/torch.py +5 -0
- package/vendor/laya-pilot/tests/guards.test.mjs +43 -0
- package/vendor/laya-pilot/tests/language.test.mjs +39 -0
- package/vendor/laya-pilot/tests/planner.test.mjs +129 -0
- package/vendor/laya-pilot/tests/readiness.test.mjs +118 -0
- package/vendor/laya-pilot/tests/real-model.smoke.mjs +74 -0
- package/vendor/laya-pilot/tests/replay-model.test.mjs +90 -0
- package/vendor/laya-pilot/tests/retries.test.mjs +270 -0
- package/vendor/laya-pilot/tests/run-state.test.mjs +162 -0
- package/vendor/laya-pilot/tests/selected-pr1.test.mjs +309 -0
- package/vendor/laya-pilot/tests/test-data.test.mjs +83 -0
- package/vendor/laya-pilot/tests/test_workflow_excel.py +162 -0
- package/vendor/laya-pilot/tests/worker_test.py +33 -0
- package/vendor/laya-pilot/tests/workflow.test.mjs +98 -0
- package/vendor/laya-pilot/worker.py +135 -0
- package/vendor/patches/0001-native-field-recipes.patch +3009 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# LayaPilot · 企业级管理后台自动化测试
|
|
2
|
+
|
|
3
|
+
[English](README.en.md) · [本地无头运行](docs/local-runtime.md) · [架构与扩展](docs/architecture.md) · [Roadmap](ROADMAP.md)
|
|
4
|
+
|
|
5
|
+
面向**企业级管理后台**,从浏览器页面**生成可回放的 Excel 测试用例**,或读取已有 Excel 执行测试。主要覆盖用户管理、客户管理等以表格、筛选、表单和增删改查为主的页面,以自动化的准确性、速度和稳定性为目标,优先使用本地或内网推理。
|
|
6
|
+
|
|
7
|
+
当前版本使用 Playwright 驱动浏览器,使用本地 Laya 或兼容的决策 API 理解字段、选择选项并匹配执行目标。执行后的断言由页面状态判断,不把模型判断直接当成通过结果。
|
|
8
|
+
|
|
9
|
+
生成阶段保留增删改查模板,由模型识别字段用途、选择填表数据策略和下拉选项类别;同类选项使用稳定顺序选择,显式 `--data` 配置仍优先。模板完成后,默认的 `discover` 操作会根据当前页面的控件和字段约束,让模型选择补充测试:无结果查询、筛选重置、取消新增、邮箱格式、数值上下界。补充测试实际执行并通过断言后才写入 Excel,回放直接复用已验证步骤。当前是有边界的候选决策,不会自动推导页面未声明的业务规则;审批、导入等尚无执行能力的入口会记入报告。
|
|
10
|
+
|
|
11
|
+
回放保留用例的步骤、数据和预期结果,由 Laya 将点击、填表、日期和下拉字段匹配到当前页面,即使只找到一个控件也会调用决策入口。相同请求可复用本轮模型缓存;模型拒绝、低置信度或选中其他值时停止该步骤,不擅自修改用例。已保存的文本、日期和下拉选项按原值精确执行;纯页面断言无需模型。
|
|
12
|
+
|
|
13
|
+
`runs/<本次运行>/执行结果.xlsx` 同时支持生成和回放:生成阶段标记为“生成时验证”,包含成功、失败、不适用及依赖阻断的记录;可回放的用例文件仍只收录已验证用例。`results.json` 的 `resultFile` 指向结果表格,`decisions.ndjson` 的 `form-field`、`form-option`、`test-discovery`、`replay-target` 分别记录字段判断、选项选择、补充测试决策和回放目标匹配。模型加载、实际推理次数与缓存命中分别统计。
|
|
14
|
+
|
|
15
|
+
项目包含一个可独立运行的公开 demo;企业专用类集适配器、内部地址、账号和模型网关配置均未纳入本仓库。**当前只实现 Playwright 浏览器驱动和 Laya 决策协议。** browser-use、Jev API 等列在 [Roadmap](ROADMAP.md),尚不能通过改一个配置项直接运行。
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
## 介绍视频
|
|
20
|
+
|
|
21
|
+
https://github.com/user-attachments/assets/940b2562-41ff-47ed-a6e0-e179d4d0847d
|
|
22
|
+
|
|
23
|
+
[在 YouTube 观看介绍视频](https://www.youtube.com/watch?v=aIZEEcTGM0w)
|
|
24
|
+
|
|
25
|
+
## 功能
|
|
26
|
+
|
|
27
|
+
| 入口 | 能力 | 产物 |
|
|
28
|
+
| ----------------- | ------------------------------------------------------------------ | ---------------------------------- |
|
|
29
|
+
| `--mode generate` | 观察页面并尝试页签、列表、筛选、表单校验及新增/查询/查看/修改/删除 | 17 列 Excel、报告、浏览器证据 |
|
|
30
|
+
| `--mode execute` | 重新定位 DOM 并回放生成的 Excel | 独立的 `执行结果.xlsx`、报告、证据 |
|
|
31
|
+
| `--excel` | 读取现有自然语言 Excel,默认只选来源结果为 `pass` 的行 | JSON、CSV、Markdown 报告 |
|
|
32
|
+
|
|
33
|
+
生成器只把**实际操作成功且页面断言通过**的流程写入 Excel。生成的工作簿有可见的步骤与预期结果,以及隐藏的结构化回放步骤;可见用例与隐藏步骤不一致时会拒绝回放。回放会创建本轮唯一命名的测试记录,并在支持的流程中清理它。错误报告可包含失败步骤、页面异常、控制台错误、接口 4xx/5xx 和截图。它不是对任意网站、任意 Excel 的完整自动化保证;审批、多账号权限、文件导入等业务流程仍需要专门适配。
|
|
34
|
+
|
|
35
|
+
## 安装与电脑配置
|
|
36
|
+
|
|
37
|
+
- Node.js **20+**、Python **3.10+**;建议 Python 3.11 或 3.12。当前浏览器实现需要 Playwright Chromium。macOS、Linux 和 Windows 可用 `node runner.mjs`;`run.sh` 是 macOS/Linux 的便捷入口。
|
|
38
|
+
- **建议优先在本机安装官方 Laya 多语言模型**,中文和英文页面共用同一模型。官方 Python 包为 `laya`,模型为 [`convaiinnovations/laya-multilingual`](https://huggingface.co/convaiinnovations/laya-multilingual)。第一次运行需要下载模型;之后可使用本地缓存或把 `LAYA_MODEL` 指向已下载目录。不要把模型权重提交到 Git。
|
|
39
|
+
- 本地模型的**实践建议**:4 核以上 CPU、**16 GB 内存**、至少 **5 GB 可用磁盘**,不要求独立显卡。本项目曾在 Apple Silicon M4 / 16 GB 上用 CPU 完成验证,模型目录约 647 MB,首次加载约 27 秒;这不是官方最低配置,也不能保证其他机器的速度。8 GB 机器可能因 Python、浏览器和模型同时运行而吃紧。API 模式不加载本地模型,仍需要 Node、浏览器和安装了 `openpyxl` 的 Python。
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone <your-repository-url> laya-pilot
|
|
43
|
+
cd laya-pilot
|
|
44
|
+
npm install
|
|
45
|
+
npx playwright install chromium
|
|
46
|
+
python3.11 -m venv .venv
|
|
47
|
+
.venv/bin/python -m pip install -r requirements-local.txt
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Windows 使用 `.venv\Scripts\python.exe` 并通过 `--python` 指定。只使用 API 决策模式时,安装 `requirements.txt` 即可,无须 `requirements-local.txt`。Laya 包和模型的最新安装说明以[官方模型卡](https://huggingface.co/convaiinnovations/laya-multilingual)及[官方 Python 项目](https://github.com/NandhaKishorM/laya)为准。
|
|
51
|
+
|
|
52
|
+
## 先体验公开 demo
|
|
53
|
+
|
|
54
|
+
在一个终端启动 demo,在另一个终端运行测试。demo 的客户数据保存在当前浏览器的 localStorage;页面每次打开会重新生成部分 DOM ID。
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm run demo
|
|
58
|
+
./run.sh --mode generate --url http://127.0.0.1:8765/customers \
|
|
59
|
+
--case-file generated-cases/customers.xlsx
|
|
60
|
+
./run.sh --mode execute --case-file generated-cases/customers.xlsx \
|
|
61
|
+
--url http://127.0.0.1:8765/customers
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
默认显示浏览器;稳定后可加 `--headless`。也可用 `./run.sh --excel examples/demo-cases.xlsx --url http://127.0.0.1:8765/customers` 体验现有 Excel 的通用执行器。生成模式会真实点击新增、修改和删除,请只对专用测试环境使用。
|
|
65
|
+
|
|
66
|
+
生成和回放支持 `--operations create,delete` 限定范围,或 `--read-only` 仅检查页签、列头和筛选控件。本地模型默认启动预热,与浏览器准备并行,业务测试开始前确认就绪;`--lazy-model` 可改为按需加载。运行期间保存 `checkpoint.json`、`progress.ndjson`,SIGINT/SIGTERM 会保留部分结果;失败或无有效用例以非零退出码结束。当前保存进度供核对,不自动断点续跑。
|
|
67
|
+
|
|
68
|
+
## 配置自己的系统
|
|
69
|
+
|
|
70
|
+
复制 [`config.example.json`](config.example.json) 为 `config.local.json`,填写页面地址和运行选项;`config.local.json` 已忽略。复制 [`.env.example`](.env.example) 为 `.env.local`,可保存仅在本机使用的密码和 API 密钥;启动时自动读取,不执行其中的 shell 命令。命令行参数优先于 shell 环境变量,shell 环境变量优先于 `.env.local`,后者优先于 JSON 配置。密码与 API 密钥**只通过环境变量、`.env.local` 或终端隐藏输入**提供,不支持写入 JSON 配置。
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
./run.sh --mode generate --config config.local.json --manual-login
|
|
74
|
+
./run.sh --mode execute --config config.local.json \
|
|
75
|
+
--case-file generated-cases/customers.xlsx
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
自动登录可传 `--user` 或 `TEST_USER`,密码使用 `TEST_PASSWORD`(可在 `.env.local` 中设置)或运行时隐藏输入。API 模式需配置 `LAYA_API_BASE`、`LAYA_API_MODEL` 和 `LAYA_API_KEY`:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
export LAYA_API_BASE='https://your-gateway.example/v1'
|
|
82
|
+
export LAYA_API_MODEL='your-decision-model'
|
|
83
|
+
export LAYA_API_KEY='your-secret-key'
|
|
84
|
+
./run.sh --mode generate --provider api --url 'https://your-test-app.example/module' --manual-login
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
本地模式默认使用 `convaiinnovations/laya-multilingual`;可以设置 `LAYA_MODEL=/path/to/model` 和 `LAYA_PYTHON=/path/to/python`。浏览器默认是 Playwright 自带 Chromium;安装本机 Chrome 后可选 `--browser-channel chrome`。`--browser-provider` 当前仅接受 `playwright`,其它值会明确报错。`--template-excel` 可指定已有的 17 列模板;不指定时生成项目自带的同列结构,不引用任何个人文件。
|
|
88
|
+
|
|
89
|
+
运行证据默认写入 `runs/`,生成文件默认写入 `generated-cases/`,两者均不纳入 Git。生成的 Excel 和报告可能含目标 URL、页面文本或测试数据,公开前请自行检查。完整 CLI 参数运行 `./run.sh --help`。
|
|
90
|
+
|
|
91
|
+
通过 `--auth-state .auth/tester.json --auth-check '登录后唯一标记的选择器'` 保存和复用登录态,支持 Cookies、localStorage、IndexedDB;sessionStorage 需额外加 `--auth-session-storage`。登录失效不会被当作成功,使用 `--auth-reset` 可重新登录。配置、退出码与状态文件的边界见[本地运行说明](docs/local-runtime.md)。默认不调用外部模型;现有 API 模式也可显式配置兼容的内网 HTTPS 决策服务。
|
|
92
|
+
|
|
93
|
+
## 开发与限制
|
|
94
|
+
|
|
95
|
+
代码统一使用 4 空格缩进、UTF-8、LF 换行,以 100 列作为自动换行参考。Prettier 负责 JS、JSON、HTML 和 Markdown,Ruff 负责 Python;工具版本固定,格式化不执行 lint 自动修复。
|
|
96
|
+
|
|
97
|
+
开发环境需要 Node.js 和 uv。执行 `npm install` 后,可运行:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm run format # 格式化整个仓库
|
|
101
|
+
npm run format:check # 只检查格式,适用于提交前或 CI
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Python 格式化首次运行时由 `uv tool run` 获取固定版本的 Ruff,后续复用缓存,不需要安装本地模型依赖。运行产物、本地配置和依赖目录不参与格式化,`package-lock.json` 由 npm 管理。
|
|
105
|
+
|
|
106
|
+
`.editorconfig` 只提供编辑器的基础约定,不会自动重排已有文件。需要保存时格式化时,在编辑器安装 Prettier、Ruff 扩展并启用对应语言的保存时格式化。
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
npm test
|
|
110
|
+
python3 -m unittest discover -s tests -p 'test_*.py'
|
|
111
|
+
LAYA_TEST_PYTHON=/path/to/python-with-openpyxl npm run test:browser
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
当前通过 DOM、标签、ARIA 角色和部分常见组件类名定位控件。页面动态重渲染后会重新观察;Canvas、封闭 Shadow DOM、缺少语义的自定义控件及复杂跨账号流程需要新增适配。架构、驱动扩展点和现有实现边界见[架构文档](docs/architecture.md)。
|
|
115
|
+
|
|
116
|
+
MIT License。Laya、Playwright 及模型权重分别遵循各自许可证。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Roadmap
|
|
2
|
+
|
|
3
|
+
[English](ROADMAP.en.md)
|
|
4
|
+
|
|
5
|
+
面向**企业级管理后台**,以**自动化准确、快速、稳定**为验收标准;优先本地或内网推理。以下区分已交付和待做项,没有承诺发布日期。
|
|
6
|
+
|
|
7
|
+
| 优先级 | 工作 | 状态与完成边界 |
|
|
8
|
+
| ------ | -------------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
9
|
+
| P0 | 本地无头运行与登录态 | 已交付:Cookies/localStorage/IndexedDB、可选 sessionStorage,账号/origin 绑定,登录成功标记与失效处理 |
|
|
10
|
+
| P0 | 运行状态与失败处理 | 已交付:workflow 逐步 checkpoint、写入前意图、目录锁、SIGINT/SIGTERM 部分结果、非零失败退出码;不含自动续跑 |
|
|
11
|
+
| P0 | 准确性与回归 | 已交付:本轮记录精确匹配与唯一性检查,失败写入不重复提交;真实 Chromium 生成/回放/500/中断/登录回归 |
|
|
12
|
+
| P0 | 模型启动与响应 | 已交付:本地模型默认启动预热,与浏览器准备并行,测试前确认就绪;支持显式按需加载,预热耗时单独记录 |
|
|
13
|
+
| P1 | 生成策略配置 | 部分交付:operations、只读范围、字段数据覆盖、可选择是否删除本轮记录;复杂数据规则和跨任务清理待做 |
|
|
14
|
+
| P1 | 更多前端组件适配 | 部分交付:原生 select、已识别树/多选、日期、独立账号和用户名、固定操作列及图标;任意自定义组件仍需适配 |
|
|
15
|
+
| P1 | 真实业务验收 | 用户管理已完成表单校验和新增、查询、修改、删除的生成与回放;分页、权限矩阵、其他模块与大规模稳定性仍待验收 |
|
|
16
|
+
| P2 | Browser Use 实验与驱动接口 | 已完成官方资料评估;暂不全量替换。具备本地/内网通用模型后再做相同断言的 A/B 实验,收益成立才抽象完整驱动契约 |
|
|
17
|
+
| P2 | Jev API 适配器 | 暂缓:缺少明确接口契约;继续支持现有 local / 兼容 api 决策协议 |
|
|
18
|
+
| P2 | 多角色与审批流程 | 未实现:需明确账号配置、切换流程与业务断言 |
|
|
19
|
+
| P2 | 用例编辑与迁移 | 未实现:需可审查地重新绑定修改后的 Excel,不能静默执行旧隐藏步骤 |
|
|
20
|
+
|
|
21
|
+
当前 `--browser-provider` 仅接受 `playwright`;`--provider` 仅接受 `local` 或 `api`。未实现的值明确报错。详见[本地运行说明](docs/local-runtime.md)和[Browser Use 评估](docs/browser-use-evaluation.md)。
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"url": "http://127.0.0.1:8765/customers",
|
|
3
|
+
"provider": "local",
|
|
4
|
+
"lazyModel": false,
|
|
5
|
+
"browserProvider": "playwright",
|
|
6
|
+
"browserChannel": "",
|
|
7
|
+
"headless": false,
|
|
8
|
+
"language": "auto",
|
|
9
|
+
"operations": ["table", "filters", "create", "search", "view", "edit", "delete"],
|
|
10
|
+
"data": {},
|
|
11
|
+
"authState": "",
|
|
12
|
+
"authCheck": "",
|
|
13
|
+
"authSessionStorage": false
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Architecture / 架构
|
|
2
|
+
|
|
3
|
+
LayaPilot targets enterprise admin applications, especially table, filter, form and CRUD workflows. The architecture prioritizes accurate assertions, predictable execution and local or intranet inference. Approvals, permission matrices and file-transfer workflows require explicit adapters and validation before they can be treated as supported enterprise features.
|
|
4
|
+
|
|
5
|
+
The public runner has three paths: `generate` and `execute` in `lib/workflow.mjs`, and natural-language workbook execution in `lib/engine.mjs`. `worker.py` imports spreadsheets through `openpyxl` and performs local Laya decisions when requested. API decisions use `lib/model.mjs`; the API key remains in the environment or a hidden prompt. Browser initialization is centralized in `lib/browser-provider.mjs`.
|
|
6
|
+
|
|
7
|
+
The browser session currently exposes a Playwright `browser`, `context`, and `page`. A new browser backend must implement the page operations used by `lib/dom.mjs`, `lib/form.mjs`, `lib/readiness.mjs`, `lib/workflow.mjs`, and `lib/engine.mjs`, plus context tracing and diagnostic events. Merely accepting `--browser-provider browser-use` would be misleading; the runner rejects it until an adapter and integration tests exist.
|
|
8
|
+
|
|
9
|
+
The decision boundary is `choose(state, criteria, meta)`, returning a choice among the supplied candidates and calibrated probabilities or an explicit failure. Local Laya and the currently compatible HTTP API implement this behavior. A future Jev API adapter needs an explicit request/response mapping, probability validation, credential handling and contract tests before it can be selected.
|
|
10
|
+
|
|
11
|
+
Generation keeps the CRUD templates, but field semantics and option groups now pass through Laya even when a rule could select them. Data recipes retain symbolic run identifiers for reproducible replay. Explicit fixture data remains an override. Natural-language Excel target matching and semantic-step fallback remain in `dom.mjs` and `planner.mjs`.
|
|
12
|
+
|
|
13
|
+
Workflow replay also grounds action targets through Laya, including a unique matching control. `lib/replay-model.mjs` matches recorded form fields against live candidates; it rejects different choices rather than replacing test inputs. Saved option paths use exact matching after the field decision. DOM ownership/scope guards and deterministic assertions remain mandatory. `replay-target` decisions and model/cache metrics make this participation observable.
|
|
14
|
+
|
|
15
|
+
After templates, the `discover` operation derives bounded candidates from observed search/reset controls, form cancellation, email types and numeric min/max attributes. Laya can accept or skip each candidate; assertions remain deterministic and replay uses model target grounding. The `assert-discovery` workbook grammar rejects unsupported actions and never submits a form. This is not an unrestricted business-test planner. Unsupported observed workflows and skipped candidates remain visible in the report. Generation exports all attempts to `执行结果.xlsx`, independently of the verified-only replay workbook.
|
|
16
|
+
|
|
17
|
+
The workbook contract is in `lib/workflow_excel.py`. The visible 17 columns are human readable; `__laya_steps__` contains a structured, validated replay plan. The digest binds the visible case ID, title, preconditions, steps and expected result to the plan. The generated Excel is a test artifact, not arbitrary executable code.
|
|
18
|
+
|
|
19
|
+
Current UI coverage is strongest for semantic HTML plus Ant Design, Element and TNTD conventions. A new component family should extend observation and form rules, then add a browser fixture test. Keep company-specific selectors, URLs, credentials and data preparation in a separate private adapter repository rather than this public core.
|
|
20
|
+
|
|
21
|
+
`lib/auth-state.mjs` restores origin/account-bound storage and validates an authenticated page marker before saving. `lib/run-state.mjs` journals workflow cases and pre-dispatch write intent using atomic JSON replacement and a per-directory lock. `lib/workflow-policy.mjs` checks allowed operations and read-only replay steps before browser startup. These are runtime boundaries, not a replacement browser-driver contract. The CLI preloads local Laya alongside browser setup and waits for readiness before business steps; `--lazy-model` opts out. API providers receive no warmup requests. Pure assertions do not request decisions; replay actions use the ready model, with identical requests eligible for the in-process cache. Integration fixtures run through the real CLI and Chromium with `npm run test:browser`, explicitly using lazy mode to avoid a dependency on model weights.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Browser Use 评估:准确、快速、稳定优先
|
|
2
|
+
|
|
3
|
+
核对日期:2026-09-29。[最新稳定发布为 0.13.10](https://github.com/browser-use/browser-use/releases/tag/0.13.10),发布说明包含 Browser Harness 0.1.13、依赖固定及 MCP 错误处理更新。本文是本项目的采用判断,不是两套引擎的性能测试结果。
|
|
4
|
+
|
|
5
|
+
## 当前值得保留的价值
|
|
6
|
+
|
|
7
|
+
[Browser Use CLI](https://docs.browser-use.com/open-source/browser-use-cli) 已提供基于 Browser Harness 的 Python 浏览器控制入口,可以连接本机 Chrome/Chromium 或现有 CDP 浏览器,也有独立的云浏览器入口。本地 CLI 本身不等于必须付费调用外部模型;已有 coding agent 可以编写操作代码。
|
|
8
|
+
|
|
9
|
+
自主 Agent 则需要通用 LLM 执行规划、观察和工具调用。[模型文档](https://docs.browser-use.com/open-source/supported-models)列出了包括 Ollama 在内的适配方式。[Agent 参数](https://docs.browser-use.com/open-source/customize/agent/all-parameters)允许配置模型、视觉、失败次数与超时。由此判断,使用本地或内网模型是可行方向,但模型的工具调用能力、上下文、硬件与延迟仍决定实际效果。当前 Laya 的候选分类协议不能直接替代完整 Agent 所需的模型协议。
|
|
10
|
+
|
|
11
|
+
[官方 Playwright 集成示例](https://docs.browser-use.com/open-source/examples/templates/playwright-integration)支持两者通过 CDP 共用 Chrome,并允许 Agent 调用确定性 Playwright 操作。因此后续可以只在未知页面探索阶段试用 Browser Use,继续用现有执行器做回放、断言与失败归因。
|
|
12
|
+
|
|
13
|
+
## 本轮判断
|
|
14
|
+
|
|
15
|
+
保留 Playwright 主路径,先完成状态复用、操作范围、断言准确性、进度保存与真实无头回归。Browser Use 保留为待验证的探索入口,不作为 P0 全量替换。
|
|
16
|
+
|
|
17
|
+
理由是当前需要稳定回放已有流程;重写浏览器层并不能直接修正重复记录定位、状态丢失或错误判成功。自主 Agent 还引入模型推理与新动作协议,收益需要实测。本轮没有安装 Browser Use、没有调用其云模型或云浏览器,也没有把它配置成可选驱动。
|
|
18
|
+
|
|
19
|
+
不能把云端 [rerunnable scripts](https://docs.browser-use.com/cloud/agent/scripts) 当作本地零推理成本回放的证明。也不能直接将 Agent 自述成功作为测试通过;最终仍由本项目的页面断言和接口/浏览器证据决定。
|
|
20
|
+
|
|
21
|
+
## 启动对比实验的条件
|
|
22
|
+
|
|
23
|
+
准备可访问的本地/内网通用模型及固定模型版本,再对同一组任务比较:
|
|
24
|
+
|
|
25
|
+
| 维度 | 采集内容 | 采用条件 |
|
|
26
|
+
| ---- | ------------------------------------------------------------ | ---------------------------------------------------- |
|
|
27
|
+
| 准确 | 独立断言通过率、误通过数、重复写入数 | 对比集无误通过和重复写入;不能只看 Agent 返回成功 |
|
|
28
|
+
| 速度 | 冷/热启动、总耗时 p50/p95、模型调用数、推理耗时 | 明确比现有方案改善目标任务,不因减少断言获得表面提速 |
|
|
29
|
+
| 稳定 | 固定任务至少重复 20 次,注入超时、HTTP 500、登录失效与重渲染 | 失败可定位,进度与证据可保留,写入不盲目重试 |
|
|
30
|
+
| 成本 | 模型服务位置、资源占用和外部推理调用数 | 只使用批准的本地/内网推理路径,外部推理调用为 0 |
|
|
31
|
+
|
|
32
|
+
现阶段缺少已验证的本地/内网通用模型、真实业务对比集与对应成绩,不能声称 Browser Use 比当前实现更准确或更快。CLI/CDP 对接和自主 Agent 的价值要分开测;前者未必需要额外模型,后者必须评估模型成本与质量。
|
|
Binary file
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# 本地无头运行与状态保存
|
|
2
|
+
|
|
3
|
+
本轮优先级是准确、快速、稳定。浏览器继续使用 Playwright;默认决策来源为本地 Laya,不自动切换外部模型。**本地模型默认启动即预热**,与浏览器准备、登录态恢复并行;业务测试开始前等待模型就绪,避免在表单中途首次加载。控制台和结果中的 `modelStartup` 单独报告预热状态与耗时。每次独立 CLI 进程仍需一次冷启动,当前没有跨进程常驻模型服务。
|
|
4
|
+
|
|
5
|
+
回放时,点击、填表、日期和下拉字段均经模型匹配当前页面目标,唯一匹配也会进入决策入口;纯断言不调用模型。相同请求可以命中本轮缓存,`modelCalls` 与 `cacheHits` 分开统计,决策日志阶段为 `replay-target`。可显式传 `--lazy-model` 或配置 `"lazyModel": true` 使用按需加载;API 来源不发送预热请求。Excel 读写仍需 Python + `openpyxl`;CI 的浏览器回归使用明确的模型替身与 `--lazy-model`,真实权重推理需单独验收。
|
|
6
|
+
|
|
7
|
+
## 操作范围与数据
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
node runner.mjs --mode generate --headless \
|
|
11
|
+
--url http://127.0.0.1:8765/customers \
|
|
12
|
+
--operations table,filters,create,search,view,edit,delete \
|
|
13
|
+
--case-file generated-cases/customers.xlsx
|
|
14
|
+
node runner.mjs --mode execute --headless \
|
|
15
|
+
--case-file generated-cases/customers.xlsx
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`--operations` 也可在 JSON 配置中写成数组。省略时仍使用完整生成策略;`--read-only` 将范围限制为 `tabs,tab-switch,table,filters`。其中 `filters` 验证名称/账号筛选输入框,以及页面提供的搜索、重置控件可见,不代表筛选业务逻辑通过。只读是执行器允许的步骤范围,不是网络层阻止所有写请求。
|
|
19
|
+
|
|
20
|
+
`search/view/edit/delete` 只操作本轮创建的数据,必须同时选择 `create`。`create,delete` 可以独立运行,不必先编辑。未选 `delete` 时保留本轮记录,报告显示 `retainedRecord`;删除失败或写入结果不确定时保留证据,不进行猜测性清理。回放时若工作簿包含超出当前范围的用例,会整体拒绝,不静默跳过。
|
|
21
|
+
|
|
22
|
+
默认根据表单字段生成数据:记录名与登录账号使用每轮唯一值,账号和可修改的用户名分别保存;按账号筛选时,修改用户名后仍使用原账号查询。过期日期默认为次日,生成 Excel 保留 `${expiryDate}`,回放时重新计算;支持已识别表单的原生日期输入以及带日期标题的 Ant 日历单元格。
|
|
23
|
+
|
|
24
|
+
下拉值来自页面真实候选。生成阶段由本地 Laya 判断选项类别,组内采用稳定顺序选择并优先叶节点。实际选择路径写入 Excel,回放由模型匹配下拉字段,再按原路径精确选择。字段判断不确定、指定值缺失或重名时失败,不自行更换用例数据。角色名称中的管理员候选不参与自动生成选择,但名称分类不能证明角色的实际权限,也不是通用业务规划模型。
|
|
25
|
+
|
|
26
|
+
`--data fields.local.json` 或配置中的 `data` 对象可选地覆盖必填文本和下拉路径,例如 `{"联系电话":"13800000000","级别":"标准"}`。它不是生成用例的前置要求。普通字段值会固化到生成的 Excel;改变这些值需重新生成。当前不提供任意数据生成脚本或跨账号清理规则。
|
|
27
|
+
|
|
28
|
+
原生 `select` 在已识别的 Ant/Element 表单项内通过 `selectOption` 选择并读取结果验证;重名选项会失败。虚拟列表、任意自定义下拉和新弹窗结构尚未获得通用支持。
|
|
29
|
+
|
|
30
|
+
## 登录态复用
|
|
31
|
+
|
|
32
|
+
首次使用可自动登录,复杂登录页可先进行一次可见的手动登录:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
node runner.mjs --mode generate --config config.local.json \
|
|
36
|
+
--manual-login --auth-state .auth/tester.json \
|
|
37
|
+
--auth-check '[data-testid="current-user"]' --read-only
|
|
38
|
+
|
|
39
|
+
node runner.mjs --mode generate --config config.local.json --headless \
|
|
40
|
+
--auth-state .auth/tester.json \
|
|
41
|
+
--auth-check '[data-testid="current-user"]' --read-only
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`authCheck` 必须是目标页登录后才出现的唯一标记。建议使用能区分测试账号的标记;仅有“没有密码框”不能证明登录成功。`--user`、配置中的 `user` 或 `TEST_USER` 是登录态账号标识,两轮须一致。文件绑定目标 origin 和该账号标识;路径仍须到达目标模块。账号标识不会取代服务端身份校验。
|
|
45
|
+
|
|
46
|
+
保存 Cookies、localStorage、IndexedDB;依赖 sessionStorage 的系统需在保存与复用时都加 `--auth-session-storage`。它只保存当前目标 origin 的 sessionStorage,不是完整浏览器 profile,不包含扩展和全部标签页。状态文件在登录校验通过后原子替换,POSIX 权限为 `0600`。`.auth/` 已忽略,不要将登录态文件提交到仓库。
|
|
47
|
+
|
|
48
|
+
失效后有 `--user` 时尝试重新登录,密码来自 `TEST_PASSWORD` 或隐藏输入;无登录方式时明确失败。`--auth-reset` 忽略旧状态,在新登录验证成功后才覆盖。自动登录支持可识别账号框、单一密码框和登录按钮;验证码、MFA、复杂 SSO 仍需要手动登录或专项适配。
|
|
49
|
+
|
|
50
|
+
## 进度、中断与退出码
|
|
51
|
+
|
|
52
|
+
以下进度文件用于 `--mode generate/execute`,每次运行使用独立 `--out` 目录:
|
|
53
|
+
|
|
54
|
+
| 文件 | 内容 |
|
|
55
|
+
| -------------------------- | ---------------------------------------------------------- |
|
|
56
|
+
| `checkpoint.json` | 已完成用例、当前用例步骤、唯一记录名、待核对写入;原子替换 |
|
|
57
|
+
| `progress.ndjson` | 用例完成、步骤完成、写入意图的顺序日志 |
|
|
58
|
+
| `results.json` / `报告.md` | 最终或中断结果、运行/用例耗时、模型调用与错误数 |
|
|
59
|
+
| `trace.zip` / `evidence/` | 登录校验完成后的浏览器轨迹与用例截图 |
|
|
60
|
+
|
|
61
|
+
写入意图在保存、删除和确认点击之前落盘。已尝试的写操作只复查结果,不自动重复提交;未确认写入会阻止后续用例继续写入,独立只读检查仍可进行。运行目录锁阻止并发覆盖;已有结果的目录也拒绝复用。
|
|
62
|
+
|
|
63
|
+
SIGINT/SIGTERM 会尽力保存部分结果与 trace 并关闭浏览器;SIGKILL、断电不能执行收尾,但之前写下的 checkpoint 可用于核对。无法保存 trace 时记录 `轨迹保存失败.json`。中断的输出目录可保留锁,改用新目录运行。
|
|
64
|
+
|
|
65
|
+
**当前没有自动断点续跑。** checkpoint 用于核对已经发生的操作,不能证明服务端尚未提交。先核对 `pendingWrite` 与运行记录名,再决定清理或重跑;重新运行会使用新的记录名。`--excel` 通用执行器复用登录态和按需模型加载,但仍沿用其原有逐用例报告,不具备上述 workflow 中断账本。
|
|
66
|
+
|
|
67
|
+
| 退出码 | 含义 |
|
|
68
|
+
| ------------- | ------------------------------------------------------- |
|
|
69
|
+
| `0` | 至少一条用例通过,其他结果仅有通过、不适用或未选择 |
|
|
70
|
+
| `1` | 用例失败、未生成、依赖阻断、无有效覆盖,或启动/导出失败 |
|
|
71
|
+
| `130` / `143` | workflow 收到 SIGINT / SIGTERM |
|
|
72
|
+
|
|
73
|
+
没有区间格式输入框时,该格式校验标为“不适用”,不会被计为通过或写入可执行用例。`metrics.modelCalls` 包括失败请求;`inferenceMs` 仅累计成功请求返回的耗时,不是完整任务耗时。
|
|
74
|
+
|
|
75
|
+
页面显示“暂无权限”等拒绝访问提示时,生成和回放会在业务步骤前失败并保存截图;没有发现所选范围内的用例也会明确失败,不把空报告当作通过。
|
|
76
|
+
|
|
77
|
+
## 可复现回归
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm test
|
|
81
|
+
python3 -m unittest discover -s tests -p 'test_*.py'
|
|
82
|
+
LAYA_TEST_PYTHON=/path/to/python-with-openpyxl npm run test:browser
|
|
83
|
+
npm run test:model # 使用 config.local.json 的本地 Python 和已下载权重,强制离线
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
浏览器回归仅访问临时启动的 `127.0.0.1` 站点或内存测试页面,使用真实无头 Chromium:覆盖生成→Excel→新会话回放、动态 DOM ID、操作范围、HTTP 500、写入期间中断、Cookie/localStorage/sessionStorage/IndexedDB 复用与失效、原生下拉、重复记录与同名前缀、独立账号/用户名、相对日期、固定操作列和没有 tabindex 的图标。产物保留在 `runs/browser-regression-*`,不调用外部模型。
|
|
87
|
+
|
|
88
|
+
浏览器回归验证执行器协议与本地 fixture,不证明任意内网站点的成功率。`test:model` 使用真实本地权重验证回放提示、控件和字段匹配及默认置信度门槛,可通过 `LAYA_TEST_CONFIG`、`LAYA_TEST_PYTHON`、`LAYA_TEST_MODEL` 指定本机配置;不会访问业务系统。真实业务页面、较慢网络、分页/虚拟列表与歧义控件仍需单独验收。本地或内网通用模型尚未进行 Browser Use 对比,见[评估记录](browser-use-evaluation.md)。
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# PR #1 选择性吸收范围
|
|
2
|
+
|
|
3
|
+
本分支从 `origin/main` 的 `5acef3f6731bc059add57b999f3c8835d9af7cf9` 创建。
|
|
4
|
+
对照 PR #1 的 `51abe5b0ebe21fc3376e64706e30286edcafac82`,逐项移植通用能力,没有合并 PR 提交历史。
|
|
5
|
+
|
|
6
|
+
## 纳入
|
|
7
|
+
|
|
8
|
+
- 保存、删除、确认后刷新前等待标准弹窗关闭及在途写请求结束;生成与回放共用。
|
|
9
|
+
- 每个逻辑步骤最多三次尝试,失败后报告原因与截图,继续独立用例;前置新增、修改失败的依赖用例明确标记阻断。
|
|
10
|
+
- 写点击发送后仅复查结果,不重复提交;不确定的结果不能记成成功。
|
|
11
|
+
- 标准 dialog、alertdialog 和明确的 dialog-content 标识识别,保留既有 AntD、Element 容器支持。
|
|
12
|
+
- 输入框的相邻 label、原生 required、原生有效性检查;label 不覆盖按钮自身文本。
|
|
13
|
+
- 禁用态校验的生成、回放、Excel 展示;同名控件有歧义时失败。
|
|
14
|
+
- 模型 JSON 格式要求,保留主版本决策阈值、默认超时及输出预算。
|
|
15
|
+
- Excel 非法控制字符清洗、回放尝试记录;Python 脚本路径改用 fileURLToPath。
|
|
16
|
+
|
|
17
|
+
## 不纳入
|
|
18
|
+
|
|
19
|
+
- 登录态缓存及 sessionStorage 自动注入、email-only 登录。
|
|
20
|
+
- 卡片列表与文本长度推断记录归属;继续要求表格记录。
|
|
21
|
+
- 用 fixed/inset-0/z-50 样式猜测弹窗、强制点击遮罩后的控件。
|
|
22
|
+
- 全局自动接受原生确认框、额外输出原始 API URL。
|
|
23
|
+
- 降低决策阈值、要求模型在证据不足时猜测、无条件延长 API 超时或增大输出预算。
|
|
24
|
+
- 固定项目测试密码、项目专用脚本、项目专用 gitignore 项。
|
|
25
|
+
|
|
26
|
+
`runner.mjs`、`lib/browser-provider.mjs`、`.gitignore` 保持主版本内容。
|
|
27
|
+
三次尝试的具体规则见 [retry-policy.md](retry-policy.md)。范围仅为生成和生成用例回放,不扩展旧版任意 Excel 执行器。
|
|
28
|
+
|
|
29
|
+
## 验证
|
|
30
|
+
|
|
31
|
+
- `node --test tests/*.test.mjs`
|
|
32
|
+
- 使用安装了 openpyxl 的 Python 执行 `python tests/test_workflow_excel.py`,验证生成、读回、结果写入及控制字符清洗。
|
|
33
|
+
- JavaScript 测试 49 项通过,Excel 往返测试 1 项通过;未进行真实后台浏览器端到端验证。
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# 生成与回放的三次尝试策略
|
|
2
|
+
|
|
3
|
+
适用范围:`--mode generate` 和 `--mode execute` 的工作流步骤。
|
|
4
|
+
|
|
5
|
+
- 每个逻辑步骤最多尝试三次,包含首次执行。成功立即继续;嵌套定位、断言等辅助函数共享预算,不叠加成九次。
|
|
6
|
+
- 定位、填写、断言等失败后重新观察或定位。生成时,创建入口优先换用尚未尝试的匹配入口;没有其他入口时可重试原入口。
|
|
7
|
+
- 保存、删除、确认先检查可操作性。一旦尝试发送点击,后两次仅等待请求并核查结果,避免重复写入。不能确认成功时仍报告失败。
|
|
8
|
+
- 三次均失败,终止当前用例的剩余步骤,记录失败步骤、各次原因和截图,继续后续独立用例。新增或修改失败时,依赖其记录状态的用例标记为依赖阻断。
|
|
9
|
+
- 截图在清理弹窗前保存;在途写请求未结束时不强行关闭弹窗。清理失败不会使其他独立用例从报告中消失。
|
|
10
|
+
- 不降低模型决策阈值,不强制点击被遮挡的控件,不要求模型在信息不足时猜测。重试成功也不会覆盖用例内已观察到的严重浏览器或接口错误。
|
|
11
|
+
|
|
12
|
+
结果文件:`results.json` 包含每条用例的 `attempts`;`报告.md` 展示逐次尝试;回放 Excel 的备注包含尝试记录。失败截图保存在 `evidence/`。
|
|
13
|
+
|
|
14
|
+
真实后台端到端验证仍需针对目标应用执行;单元测试不代表所有页面结构均已兼容。
|
|
Binary file
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Local regression fixture only. Random IDs/order and fresh DOM on every navigation.
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
const port = Number(process.env.PORT || 8765);
|
|
5
|
+
const html = await fs.readFile(new URL('./demo.html', import.meta.url), 'utf8');
|
|
6
|
+
http.createServer((req, res) => {
|
|
7
|
+
if (req.url === '/favicon.ico') {
|
|
8
|
+
res.writeHead(204);
|
|
9
|
+
res.end();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (req.url === '/api/save-fail') {
|
|
13
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
14
|
+
res.end('{"message":"fixture server error"}');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
18
|
+
res.end(html.replace('__SAVE_ERROR__', JSON.stringify(process.env.DEMO_SAVE_HTTP_500 === '1')));
|
|
19
|
+
}).listen(port, '127.0.0.1', () => console.log('演示系统 http://127.0.0.1:' + port));
|