browser_visual_compare
Capture a screenshot of the current page, compare it against a visual baseline, and receive diff metrics and artifact paths to identify UI changes.
Instructions
Capture an actual PNG of the current page, compare against the same-named visual baseline, generate a diff PNG, and return diffPixels, diffRatio, passed flag, and artifact paths.
中文详情:
用途:截取当前页面 actual PNG 与同名视觉基线对比,生成 diff PNG 并返回差异指标和产物路径
何时使用:UI 改动后回归对比时;多环境(dev/staging/prod)视觉一致性验证时;组件样式调整后差异检测时;CI 中视觉回归门禁时
输出:{ ok: boolean, name: string, baselinePath: string, actualPath: string, diffPath: string, diffPixels: number, diffRatio: number, passed: boolean, threshold: number }
参数:
name (string, 必填):要对比的基线名称,不含扩展名
selector (string, 可选):CSS 选择器;需与基线截图范围一致
fullPage (boolean, 可选):是否全页截图,默认 true;selector 存在时忽略
maskSelectors (array, 可选):截图前额外遮挡/脱敏的 CSS 选择器列表,用于忽略动态区域
maxDiffPixelRatio (number, 可选):允许的最大差异像素比例,默认 0.01
sessionName (string, 可选):浏览器会话名称,默认当前活跃会话
错误:基线不存在抛出 'Baseline not found, run browser_visual_baseline first';selector 无匹配抛出 'element not found'
示例:{"name":"login-page-baseline","maxDiffPixelRatio":0.005,"maskSelectors":[".timestamp"]}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | 要对比的基线名称,不含扩展名 | |
| fullPage | No | 是否全页截图,默认 true;selector 存在时忽略 | |
| selector | No | 可选 CSS 选择器;需与基线截图范围一致 | |
| sessionName | No | 浏览器会话名称,默认当前活跃会话 | |
| maskSelectors | No | 截图前额外遮挡/脱敏的 CSS 选择器列表,用于忽略动态区域 | |
| maxDiffPixelRatio | No | 允许的最大差异像素比例,默认 0.01 |