Visual regression testing

From aj-geddes/useful-ai-prompts · View interactive version

Visual regression testing is an AI agent skill from the GitHub repository aj-geddes/useful-ai-prompts. Detect unintended visual changes in UI by comparing screenshots across versions. Use for visual regression, screenshot diff, Percy, Chromatic, UI testing, and visual validation.

How to use this skill

Skill file

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

Quick Start

Minimal working example:

// tests/visual/homepage.spec.ts
import { 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:

| Guide | Contents |

|---|---|

| Playwright Visual Testing | Playwright Visual Testing |

| Percy Visual Testing | Percy Visual Testing |

| Chromatic for Storybook | Chromatic for Storybook |

| Cypress Visual Testing | Cypress Visual Testing |

| BackstopJS Configuration | BackstopJS Configuration |

| Handling Dynamic Content | Handling Dynamic Content |

| Testing Responsive Components | Testing Responsive Components |

Best Practices

✅ DO

❌ DON'T

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.