Visual Regression Testing

aj-geddes/useful-ai-prompts/skills/visual-regression-testing

作者 aj-geddes3f5182cfd739无许可证355 个星标收录于 2026年10月8日更新于 2026年10月8日仓库7个月前更新

Detect unintended visual changes in UI by comparing screenshots across versions. Use for visual regression, screenshot diff, Percy, Chromatic, UI testing, and visual validation.

AI 生成的概览

通过跨版本比较截图来检测 UI 中非预期的视觉变化,指导视觉回归测试。

功能
该技能提供用于搭建 UI 组件与页面视觉回归测试的说明和参考指南。内容涵盖截取屏幕截图并与基线对比,以发现 CSS 缺陷、布局偏移和设计回归。它包含 Playwright、Percy、Chromatic、Cypress 和 BackstopJS 的指导,以及处理动态内容和响应式组件的方法。它产出的是测试配置与实践建议,本身不运行脚本。
适用场景
当你需要检测 Web UI 中非预期的视觉变化时使用,例如发现 CSS 回归、验证不同视口下的响应式布局,或在拉取请求中审查视觉差异。它也适用于验证设计系统组件和主题变更。
运行要求
不附带脚本,仅为说明和参考文档。按示例操作需要视觉测试工具链,如 Playwright、Percy、Chromatic、Cypress 或 BackstopJS,以及浏览器环境和基线截图。

Visual Regression Testing

Table of Contents

Overview

Visual regression testing captures screenshots of UI components and pages, then compares them across versions to detect unintended visual changes. This automated approach catches CSS bugs, layout issues, and design regressions that traditional functional tests miss.

When to Use

  • Detecting CSS regression bugs
  • Validating responsive design across viewports
  • Testing across different browsers
  • Verifying component visual consistency
  • Catching layout shifts and overlaps
  • Testing theme changes
  • Validating design system components
  • Reviewing visual changes in PRs

Quick Start

Minimal working example:

typescript
// tests/visual/homepage.spec.tsimport { test, expect } from "@playwright/test";
test.describe("Homepage Visual Tests", () => {  test("homepage matches baseline", async ({ page }) => {    await page.goto("/");
    // Wait for images to load    await page.waitForLoadState("networkidle");
    // Full page screenshot    await expect(page).toHaveScreenshot("homepage-full.png", {      fullPage: true,      maxDiffPixels: 100, // Allow small differences    });  });
  test("responsive design - mobile", async ({ page }) => {    await page.setViewportSize({ width: 375, height: 667 }); // iPhone SE    await page.goto("/");
    await expect(page).toHaveScreenshot("homepage-mobile.png");  });
  test("responsive design - tablet", async ({ page }) => {// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Playwright Visual Testing [blocked]Playwright Visual Testing
Percy Visual Testing [blocked]Percy Visual Testing
Chromatic for Storybook [blocked]Chromatic for Storybook
Cypress Visual Testing [blocked]Cypress Visual Testing
BackstopJS Configuration [blocked]BackstopJS Configuration
Handling Dynamic Content [blocked]Handling Dynamic Content
Testing Responsive Components [blocked]Testing Responsive Components

Best Practices

✅ DO

  • Hide or mock dynamic content (timestamps, ads)
  • Test across multiple viewports
  • Wait for animations and images to load
  • Use consistent viewport sizes
  • Disable animations during capture
  • Test interactive states (hover, focus)
  • Review diffs carefully before approving
  • Store baselines in version control

❌ DON'T

  • Test pages with constantly changing content
  • Ignore small legitimate differences
  • Skip responsive testing
  • Forget to update baselines after design changes
  • Test pages with random data
  • Use overly strict thresholds (0% diff)
  • Skip browser/device variations
  • Commit unapproved diffs

来源与署名

来源:aj-geddes/useful-ai-prompts位于skills/visual-regression-testing提交3f5182c

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架