add-regression-point
为已有 PageObject 增量添加回归测试点。触发:新增测试点、添加回归点、add test point、增加覆盖、扩展页面方法。
替换占位定位符为真实选择器(六级优先级)。触发:替换定位符、locator、selector、定位失败、元素找不到、DOM 分析。
$ npx -y skills add danielsuo117/velocitai --skill locator-replacer --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/locator-replacerContext preview
The summary Claude sees to decide when to auto-load this skill.
替换占位定位符为真实选择器(六级优先级)。触发:替换定位符、locator、selector、定位失败、元素找不到、DOM 分析。
name: locator-replacer description: 替换占位定位符为真实选择器(六级优先级)。触发:替换定位符、locator、selector、定位失败、元素找不到、DOM 分析。
---
按优先级从高到低,**逐级尝试,选中即停**。优先使用页面上已有的语义化信息, 避免依赖需要前端额外配合的属性。
| 级别 | 策略 | 抗什么 | 代价 | |------|------|--------|------| | **P0** | ARIA role + 可见文本 | CSS 重构、构建哈希 | 文案变更需同步 | | **P1** | 可见文本 | CSS 重构、构建哈希 | 文案变更需同步、可能不唯一 | | **P2** | 表单特有属性(name/placeholder/type) | 样式与文案变更 | 仅适用于表单控件 | | **P3** | 语义化 CSS class / id | 文案变更 | 样式重构即失效 | | **P4** | `data-testid` | 几乎全部 | **需前端配合添加** | | **P5** | 相对 XPath / CSS 结构 | —— | 最脆弱,最后手段 |
**完整写法、判断依据与代码示例** → [references/priority-levels.md](./references/priority-levels.md)
使用 agent-browser 打开目标页面,获取交互元素信息(工具选型遵循 [agent-behavior P0.4](../../rules/agent-behavior/agent-behavior.md),agent-browser 未安装时降级到 Playwright MCP):
操作步骤:
1. browser_navigate → 访问目标页面(已认证状态)
2. browser_snapshot → 获取页面无障碍树(accessibility tree)
3. browser_evaluate → 执行 JS 提取元素属性:
- document.querySelectorAll('[data-testid]') → 已有 testid
- document.querySelectorAll('[role]') → ARIA role
- document.querySelectorAll('button, a, input') → 交互元素对照页面对象中的每个占位定位符,按 P0→P5 逐级尝试,命中即停:
| 检查顺序 | 条件 | 使用 | |---------|------|------| | P0 | 有 role + name | `role=button[name='...']` | | P1 | text= 唯一且稳定 | `text=...`(标记"已验证唯一")| | P2 | 表单属性(placeholder/name/type) | `[placeholder='...']` | | P3 | 稳定 CSS class(非哈希) | `css=.xxx` | | P4 | 有 data-testid | `[data-testid='...']` | | P5 | 以上均无 | 相对 XPath(≤3 层) |
class <PageName>(BasePage):
# 定位符 — 已替换为真实选择器(<日期>)
<PRIMARY_ACTION_BTN> = "role=button[name='<按钮文案>']" # P0: ARIA role
<SECONDARY_LINK> = "text=<链接文案>" # P1: text(已验证唯一)
PAGE_IDENTIFIER = "role=heading[name='<页面标题>']" # P0: ARIA role**更新规则:**
# 在对应角色的回归文件中跑指定用例(运行前向用户确认 --env,见 agent-behavior P0.2) pytest framework/tests/<role>/test_<role>_flow.py --env=<pre|prod> -v -k "test_<story_name>"
更新 [docs/regression-points.md](../../docs/regression-points.md) 中对应 PageObject 的"关键定位符"段。
---
替换完成后,逐项确认:
---
同一文本重复、元素无稳定属性、构建后批量失效等症状的处理方式 → [references/troubleshooting.md](./references/troubleshooting.md)
Next-generation UI automation harness powered by Python & Playwright. Chat with AI Agents to seamlessly generate, architect, and execute enterprise-grade UI test code.
为已有 PageObject 增量添加回归测试点。触发:新增测试点、添加回归点、add test point、增加覆盖、扩展页面方法。
浏览器 viewport / headless / 超时分层配置。触发:viewport、浏览器配置、导航超时、headless、slow_mo、incognito。
共享 page 下用例离开起点后必须 UI 返回并断言。触发:往返闭合、case round trip、复位超时、scope 共享 page。
一键生成 PageObject + 配套测试。触发:新增页面、生成页面、gen page、create page、添加页面对象。