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 從公開儲存庫中收錄這些內容。

檢舉或申請下架