Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计通过

visual-testing视觉测试

Agent Skill

用于辅助界面设计、视觉规范、排版、配色、布局和交互体验优化。它适合让 Agent 根据产品场景整理页面结构、生成 UI 方案、检查视觉一致性或改进组件层级。使用时需要结合现有品牌、设计系统和用户任务,不应只堆装饰元素;涉及真实页面改动时,应通过截图或浏览器预览检查文本溢出、对齐和响应式表现。

总安装

282

周安装

12

GitHub Stars

4

下载量

99
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:visual-testing(视觉测试)
来源仓库:https://github.com/petrkindlmann/qa-skills
仓库路径:skills/visual-testing
安装命令:
npx skills add https://github.com/petrkindlmann/qa-skills --skill visual-testing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/petrkindlmann/qa-skills --skill visual-testing

简介

用于辅助界面设计、视觉规范和交互体验优化。visual-testing 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

  • 适合整理页面结构、生成 UI 方案或检查视觉一致性。
  • 使用时需结合品牌、设计系统和用户任务,避免堆砌装饰元素。
  • 涉及真实页面改动时应通过截图或预览检查文本溢出和对齐。
  • 响应式表现需在多设备上验证,确保布局适配。

SKILL.md


Discovery Questions

Before implementing visual testing, gather context. Check .agents/qa-project-context.md first -- if it exists, use it and skip questions already answered there.

Tool Selection

  • Playwright built-in or dedicated tool? Playwright's toHaveScreenshot is free and requires no external service. Dedicated tools (Chromatic, Percy, Argos) add review workflows, browser rendering farms, and historical tracking. Choose based on team size and review needs.
  • Storybook in the project? If yes, Chromatic is the natural fit -- it captures every story as a visual test. If no Storybook, Playwright or Percy are better options.
  • CI platform? Visual testing generates large artifacts (screenshots, diffs). Ensure CI has storage and the pipeline can handle the extra time.

Scope

  • Full-page or component screenshots? Full-page catches layout issues but is sensitive to unrelated changes. Component-level screenshots are more stable and focused.
  • Which pages/components are visually critical? Not everything needs visual testing. Focus on user-facing pages, marketing pages, design system components, and complex layouts.
  • Which viewports? Desktop, tablet, mobile? Define the viewport matrix upfront.

Dynamic Content

  • What content changes between runs? Dates, timestamps, user-generated content, analytics IDs, randomized content, advertisements, avatars. All must be masked or frozen.
  • Are there animations or transitions? These cause false positives if not disabled or waited for.
  • Does the page load external resources? Fonts, images from CDNs, third-party widgets can vary between runs.

Core Principles

1. Visual Tests Catch What Functional Tests Miss

Functional tests assert behavior: "clicking Submit shows a success message." Visual tests assert appearance: "the success message is green, correctly positioned, and does not overlap the form." Both are needed. Visual tests complement functional tests, they do not replace them.

2. Baseline Management Is the Hard Part

Taking screenshots is easy. Managing baselines -- updating them when design changes intentionally, reviewing diffs, coordinating approvals across a team -- is the real challenge. Invest in the review workflow early.

3. Dynamic Content Causes False Positives

Any content that changes between runs (timestamps, avatars, ads, random IDs) produces pixel differences that are not real regressions. Aggressively mask or freeze dynamic content. A visual test suite with a 10% false positive rate will be ignored within a month.

4. Threshold Tuning Is Iterative

The right diff threshold depends on the specific component, rendering engine, and what you consider "visually different." Start strict (zero tolerance), observe false positives, and loosen thresholds per-component as needed. Document why each threshold was chosen.

5. Screenshots Are Artifacts, Not Test Results

The screenshot file itself is evidence. Store it, version it, and make it accessible for review. A test that says "visual diff detected" without showing the diff is useless.


Playwright Visual Comparisons

Playwright's built-in toHaveScreenshot and toMatchSnapshot provide visual regression testing without external services.

Basic Screenshot Comparison

import { test, expect } from '@playwright/test';

test('dashboard matches baseline', async ({ page }) => {
  await page.goto('/dashboard');
  // Wait for all data to load before capturing
  await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
  await expect(page.getByTestId('chart-container')).toBeVisible();

  await expect(page).toHaveScreenshot('dashboard.png');
});

On first run, this creates the baseline screenshot. On subsequent runs, it compares against the baseline and fails if pixels differ beyond the threshold.

Configuration Options

// Comparison with explicit thresholds
await expect(page).toHaveScreenshot('dashboard.png', {
  maxDiffPixels: 100,          // Allow up to 100 pixels to differ
  // OR
  maxDiffPixelRatio: 0.01,     // Allow up to 1% of pixels to differ
  threshold: 0.2,              // Per-pixel color difference tolerance (0-1)
  animations: 'disabled',      // Freeze CSS animations and transitions
  caret: 'hide',               // Hide blinking cursor
  timeout: 15000,              // Wait up to 15s for stable screenshot
});

When to use which threshold:

OptionUse When
maxDiffPixels: 0Pixel-perfect components (icons, logos, design system atoms)
maxDiffPixels: 50-100Full-page layouts where antialiasing varies slightly
maxDiffPixelRatio: 0.01Full-page screenshots where absolute pixel count varies with viewport
threshold: 0.2Cross-browser testing where color rendering differs slightly

playwright.config.ts Visual Settings

import { defineConfig } from '@playwright/test';

export default defineConfig({
  expect: {
    toHaveScreenshot: {
      maxDiffPixelRatio: 0.005,    // Global default: 0.5% tolerance
      animations: 'disabled',
      caret: 'hide',
    },
    toMatchSnapshot: {
      maxDiffPixelRatio: 0.005,
    },
  },
  projects: [
    {
      name: 'visual-desktop',
      use: {
        viewport: { width: 1280, height: 720 },
        colorScheme: 'light',
      },
      testMatch: /.*visual.*\.spec\.ts/,
    },
    {
      name: 'visual-mobile',
      use: {
        viewport: { width: 375, height: 667 },
        colorScheme: 'light',
        isMobile: true,
      },
      testMatch: /.*visual.*\.spec\.ts/,
    },
  ],
});

Masking Dynamic Regions

test('profile page visual test', async ({ page }) => {
  await page.goto('/profile');
  await expect(page.getByRole('heading', { name: 'Profile' })).toBeVisible();

  await expect(page).toHaveScreenshot('profile.png', {
    mask: [
      page.getByTestId('user-avatar'),        // User-specific image
      page.getByTestId('last-login-time'),     // Timestamp
      page.getByTestId('activity-feed'),       // Dynamic content
    ],
    maskColor: '#FF00FF',                       // Visible mask color for debugging
  });
});

Freezing Dynamic Content Before Capture

test('dashboard with frozen data', async ({ page }) => {
  // Freeze time to eliminate timestamp differences
  await page.clock.install({ time: new Date('2026-01-15T10:00:00Z') });

  // Stub API to return deterministic data
  await page.route('**/api/dashboard', async (route) => {
    await route.fulfill({
      json: {
        stats: { users: 1234, revenue: 56789 },
        chart: [10, 20, 30, 40, 50],
      },
    });
  });

  // Disable font loading to prevent FOUT (Flash of Unstyled Text)
  await page.route('**/*.woff2', (route) => route.abort());

  await page.goto('/dashboard');
  await expect(page.getByTestId('chart-container')).toBeVisible();

  // Wait for animations to complete
  await page.evaluate(() => {
    document.getAnimations().forEach((a) => a.finish());
  });

  await expect(page).toHaveScreenshot('dashboard-frozen.png', {
    animations: 'disabled',
  });
});

Handling Animations

Two options: use Playwright's built-in animations: 'disabled' in toHaveScreenshot (preferred), or inject a style tag that zeros out animation-duration and transition-duration for all elements. Always wait for the element to be visible before capturing.

Component-Level Screenshots

test('data table renders correctly with various states', async ({ page }) => {
  await page.goto('/admin/users');
  await expect(page.getByRole('table')).toBeVisible();

  // Screenshot just the table component, not the full page
  const table = page.getByRole('table', { name: 'Users' });
  await expect(table).toHaveScreenshot('users-table.png');
});

test('empty state renders correctly', async ({ page }) => {
  await page.route('**/api/users', (route) => route.fulfill({ json: { users: [] } }));
  await page.goto('/admin/users');

  const emptyState = page.getByTestId('empty-state');
  await expect(emptyState).toHaveScreenshot('users-empty-state.png');
});

test('error state renders correctly', async ({ page }) => {
  await page.route('**/api/users', (route) => route.fulfill({ status: 500 }));
  await page.goto('/admin/users');

  const errorState = page.getByTestId('error-state');
  await expect(errorState).toHaveScreenshot('users-error-state.png');
});

Updating Baselines

# Update all baselines (when design intentionally changes)
npx playwright test --update-snapshots

# Update baselines for specific tests only
npx playwright test visual-dashboard --update-snapshots

# Review what changed before committing
git diff --stat  # See which baseline files changed
# Open the test report to visually review each change
npx playwright show-report

Baseline update workflow:

  1. Design change is implemented
  2. Run visual tests -- they fail with expected diffs
  3. Review each diff: is the change intentional?
  4. Update baselines: npx playwright test --update-snapshots
  5. Commit updated baselines with a descriptive message referencing the design change
  6. PR reviewers verify the baseline changes look correct

Dedicated Visual Testing Tools

Tool Comparison

ToolBest WhenIntegrationKey Feature
ChromaticProject uses StorybookEvery story = a visual testReview/approval UI, cross-browser
PercyNo Storybook, need multi-browserAny test framework via SDKMulti-width captures, CSS overrides
Argos CIOpen-source preference, budget-consciousPlaywright reporterSelf-hosting option, generous free tier

Chromatic (Storybook)

# GitHub Actions
- uses: chromaui/action@latest
  with:
    projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
    exitZeroOnChanges: true    # Changes go to review, not CI failure
    onlyChanged: true          # Only test stories affected by code changes

Workflow: push code, CI captures screenshots, reviewers approve/reject in Chromatic UI, PR merges after approval.

Percy (Any Framework)

import { percySnapshot } from '@percy/playwright';

test('checkout page visual', async ({ page }) => {
  await page.goto('/checkout');
  await percySnapshot(page, 'Checkout Page', {
    widths: [375, 768, 1280],
    percyCSS: `.ad-banner { display: none !important; }`,
  });
});
// CI: npx percy exec -- npx playwright test --grep @visual

Argos CI (Open Source)

import { argosScreenshot } from '@argos-ci/playwright';

test('pricing page visual', async ({ page }) => {
  await page.goto('/pricing');
  await argosScreenshot(page, 'pricing-page', { viewports: ['macbook-16', 'iphone-x'] });
});

Responsive Visual Testing

Test at breakpoints where layout changes, not at every possible viewport. Define a viewport matrix based on analytics data.

const VISUAL_VIEWPORTS = [
  { name: 'mobile', width: 375, height: 667, isMobile: true },
  { name: 'tablet', width: 768, height: 1024, isMobile: false },
  { name: 'desktop', width: 1280, height: 720, isMobile: false },
] as const;

for (const vp of VISUAL_VIEWPORTS) {
  test.describe(`Visual @ ${vp.name}`, () => {
    test.use({ viewport: { width: vp.width, height: vp.height }, isMobile: vp.isMobile });

    test('homepage layout', async ({ page }) => {
      await page.goto('/');
      await expect(page.getByRole('main')).toBeVisible();
      await expect(page).toHaveScreenshot(`homepage-${vp.name}.png`, {
        fullPage: true,
        animations: 'disabled',
      });
    });
  });
}

Alternatively, use Playwright projects (in playwright.config.ts) to define viewport configurations and run all visual tests across them automatically.


Baseline Management

Git-Stored Baselines

Playwright stores baselines alongside test files by default.

e2e/
  tests/
    visual/
      dashboard.visual.spec.ts
      dashboard.visual.spec.ts-snapshots/
        dashboard-chromium-linux.png         # Platform-specific baselines
        dashboard-chromium-darwin.png
        dashboard-firefox-linux.png

Pros: Baselines are versioned with the code, reviewed in PRs, and available offline.

Cons: Repository size grows. Large baseline files bloat git history.

Use Git LFS (.gitattributes: *.png filter=lfs diff=lfs merge=lfs -text) to prevent repository bloat. Customize snapshot paths with snapshotPathTemplate in playwright.config.ts.

Platform-Specific Baselines

Playwright renders differently across operating systems. Use Docker in CI for consistency:

jobs:
  visual-tests:
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/playwright:v1.50.0-noble
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npx playwright test --grep @visual

Generate baselines in CI (not locally) so they always match the CI rendering environment.

Review and Approval Workflow

  1. CI detects visual diff, uploads expected/actual/diff images as artifacts
  2. PR reviewer examines diffs
  3. Intentional change: update baselines (--update-snapshots), re-commit
  4. Unintentional regression: fix the code, re-run tests

Anti-Patterns

Full-Page Screenshots Without Masking

Capturing entire pages without masking dynamic content (timestamps, user avatars, live data). Every run produces diffs that are not real regressions. The team stops trusting visual tests and ignores them. Always mask dynamic regions and freeze time-dependent content.

No Artifact Storage in CI

Running visual tests in CI without uploading screenshot artifacts. When a test fails, there is no way to see the actual vs. expected image. The developer has to reproduce locally, which may produce different results due to platform rendering differences. Always upload screenshots, diffs, and test reports as CI artifacts.

No Review Process for Baseline Updates

Running --update-snapshots and committing without reviewing the changes. Regressions get baked into baselines and become invisible. Every baseline update should go through code review. Reviewers must look at the before/after images, not just the file diff.

Testing Visual Stability of Unstable Components

Writing visual tests for components that change frequently by design (A/B tests, personalized content, frequently updated marketing banners). These tests fail constantly with intentional changes, creating noise. Either exclude these components from visual testing or stub their content.

Pixel-Perfect Thresholds on Full Pages

Setting maxDiffPixels: 0 on full-page screenshots. Sub-pixel rendering differences across browser versions, OS updates, and font rendering changes produce false positives. Use maxDiffPixelRatio: 0.005 (0.5%) for full pages. Reserve zero tolerance for small, critical components like logos and icons.

No Consistent Rendering Environment

Running visual tests on developer machines (macOS, Windows, various displays) and expecting baselines to match. Font rendering, antialiasing, and scaling differ across platforms. Run visual tests in a consistent CI environment (Docker) and generate baselines there.

Skipping Animation Handling

Not disabling animations before taking screenshots. CSS transitions and JavaScript animations captured mid-frame produce random diffs. Use animations: 'disabled' in Playwright or inject CSS to zero-out animation durations.


Done When

  • Baseline screenshots captured in CI (not locally) and committed to the repository.
  • Diff threshold configured per component type (e.g., maxDiffPixels: 0 for icons, maxDiffPixelRatio: 0.005 for full pages).
  • Dynamic content masked or frozen before capture (timestamps, user avatars, live API data).
  • CI pipeline blocks merge when a visual diff exceeds the configured threshold.
  • Review workflow defined: who reviews diffs, how intentional changes get baseline updates, and PR reviewers sign off on baseline commits.

Related Skills

  • playwright-automation -- The foundation for Playwright-based visual tests; Page Object Model, fixtures, and test structure apply to visual tests too.
  • ci-cd-integration -- Pipeline configuration for running visual tests, uploading artifacts, and integrating review workflows.
  • cross-browser-testing -- Visual tests across browsers catch rendering differences; viewport matrix and browser project configuration overlap.
  • qa-project-context -- The project context file captures which pages are visually critical and what dynamic content exists.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.93%
按下载量换算36

Claude

31.87%
按下载量换算32

Cursor

19.58%
按下载量换算19

Gemini CLI

9.06%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills