Logo Playwright Visual Testing

Playwright Visual Testing

Tổ chức
uiverify
playwright-visual-testing

Make @uiverify/playwright (archive-replay) captures deterministic so real-page visual tests stop coming back "changed" without a real change (flaky diffs). Use when driving a real page — your app under test, a staging build, or live production — and the diff flakes. A symptom-to-lever checklist for the run-to-run variation you probably have - feature flags, live data, the clock, third-party widgets, and dynamic layouts. The lever is almost always "stop the variation at record time" — the archive bakes in whatever the page was.

Tổng quan

Nhà phát hànhuiverify
Kho mãuiverify
Tên kỹ năngplaywright-visual-testing
Sao
27
Bản fork
1
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Đầy đủ trong hướng dẫn

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được uiverify công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Playwright Visual Testing trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/uiverify/uiverify/tree/main/packages/skills/skills/playwright-visual-testing
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/uiverify/uiverify.git /tmp/uiverify
mkdir -p .claude/skills
cp -r /tmp/uiverify/packages/skills/skills/playwright-visual-testing .claude/skills/playwright-visual-testing
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Playwright Visual Testing trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Playwright Visual Testing ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Playwright Visual Testing không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Deterministic Playwright captures (archive-replay)

Mental model

@uiverify/playwright captures each test's final DOM + every resource the page loaded into an archive; UI Verify re-renders and pixel-diffs that archive server-side. So:

Whatever the page was at the instant of capture is baked into the archive forever. Your job is to drive the page to one canonical state before the snapshot. UI Verify can't un-see a random A/B variant, a live feed, or a piece of lazy content that never loaded.

The snapshot fires automatically at the end of every test that passes or fails (a failed one too, so a broken page shows up as a visual change rather than vanishing from the build; a test that times out is skipped), so your beforeEach + navigation is the determinism surface. Integration is one import:

diff
- import { test, expect } from '@playwright/test';
+ import { test, expect } from '@uiverify/playwright';

What UI Verify handles (don't hand-fix these): before each snapshot, @uiverify/playwright waits for the next stable frame: finite requestAnimationFrame animations (a chart's line-draw) reach their last frame, fonts and images load (loading="lazy" images below the fold included), and the page size stops changing. Then UI Verify re-renders the archived DOM with prefers-reduced-motion emulated. So pixel-level settling — waiting on document.fonts.ready, a finite entry animation, image decode — is not your job. Your job is narrower: make sure the content and state the archive records is the same every run.

One caveat on "animations": the freeze is replay-side, via reduced-motion emulation — the archive does not bake a frozen frame. A CSS animation that honors prefers-reduced-motion freezes for free; an infinite CSS/JS animation that ignores it keeps running on replay and lands on a random frame (recipe 8), and a <canvas>/requestAnimationFrame loop is beyond the media query entirely (recipe 9): the snapshot's wait gives up on an endless loop after about 4 s, captures the frame on screen, and prints … was still animating with the snapshot's id. Those live inside your app, so the fix does too.

The core skill: recognize the class, then pull the lever at record time

Everything below is the same move — something rendered differently run-to-run and it wasn't a real change; find what injected the variation and pin it before the snapshot.

Symptom in the diffCause classLever
Whole page reflows; height differs between runsFeature flag / A-B experiment rendering a different variant per load (Optimizely, LaunchDarkly, VWO, your own)Stub the flag calls so one fixed variant renders → recipe 1
A list / feed / counts differLive data from an APIMock the endpoint with a fixed response → recipe 2
Timestamps, "today", a year, a chart's day axis driftThe clock (Date.now) at render timeFreeze Date before navigation → recipe 3
A banner / chat / consent overlay appears or shiftsThird-party widget injecting DOMStub or dismiss it → recipe 1 + 4
Blank/placeholder where a section should beContent that mounts on scroll (an IntersectionObserver, an infinite list), so it never reached the DOMScroll to it at record time → recipe 5
Same content, packed or ordered differently each runDynamic layout that reflows or reorders on its ownMask it (or pin a fixed order/size) → recipe 6
An infinite JS animation the capturer can't stop (a charting lib's loop, a <canvas> spinner)App-driven animation with no final frameBranch the component on capture and render the end state → recipe 7
A different logo/mascot/hero or list order each run — a whole-element diff, not a pixel shiftMath.random() in the render body, run at SSR time in Next.js/RemixPin the variant on isUIVerify() + UI_VERIFY=1 on the app server → recipe 10
An infinite CSS keyframe animation on a different frameCSS animation that ignores prefers-reduced-motionHonor the media query in the app's CSS → recipe 8
A <canvas> (particles, chart, background) diffs every runrequestAnimationFrame loop the media query can't reachDraw one static frame on isUIVerify() → recipe 9
The capture is a skeleton / spinner, not the loaded pageSnapshot fired before the data arrivedWait for the real content (networkidle) → recipe 12

Prefer removing a whole class at the source: test a build/staging with flags and third-party scripts off and rows 1 and 4 disappear before you write any code.

Recipes

1. Stub feature-flag / third-party scripts (register in beforeEach, before goto):

ts
await page.route(/optimizely|optly|launchdarkly|segment|intercom/i, (route) =>
  route.fulfill({ status: 204, body: '' }).catch(() => undefined),
);

Use fulfill({ status: 204 }), not route.abort() — an aborted request reads as pending network activity and can hang the page's readiness wait. A 204 completes it empty: the script "loads," resolves no variant, and the page renders its control DOM. Identify the culprit by loading the page a few times and watching document.body.scrollHeight flip between values.

2. Mock live data: intercept the API route and fulfill a fixed JSON fixture — same shape every run.

ts
await page.route('**/api/items', (route) =>
  route.fulfill({ json: fixtures.items }),
);

3. Freeze the clock (before navigation — it changes what the app renders into the DOM). Use Playwright's built-in clock so Date, Date.now(), and Date()-without-new all stay correct:

ts
await page.clock.setFixedTime(new Date('2020-01-01T00:00:00Z'));

4. Dismiss overlays (best-effort; absent = fine):

ts
await page.getByRole('button', { name: 'Accept All' }).click({ timeout: 4000 }).catch(() => {});

5. Trigger content that mounts on scroll so it lands in the archive. Native loading="lazy" images (Next.js <Image> included) are loaded for you before the snapshot. What isn't is content your app only mounts once it's scrolled into view (an IntersectionObserver, an infinite list, a "load more" on scroll): it was never in the DOM, so it was never recorded. Scroll it into view before the snapshot:

ts
await page.evaluate(async () => {
  for (let y = 0; y < document.body.scrollHeight; y += innerHeight) {
    scrollTo(0, y);
    await new Promise((r) => setTimeout(r, 60));
  }
  scrollTo(0, 0);
});

6. Mask what can't be pinned. Last resort for content that is supposed to differ and can't be pinned at the source (a third-party embed, a map, an ad slot, a live feed): add data-uiverify-ignore to the element. UI Verify paints its box solid black on every capture, so its content never reaches the diff. The box's size and position still diff (give it a fixed size), and nothing inside it is checked, so mask only what you can't pin and fix what you own. Docs.

tsx
<aside data-uiverify-ignore style={{ width: 320, height: 256 }}><AdSlot /></aside>

On a page you don't own, set the attribute from the test before the snapshot; the archive keeps it and replay masks the box:

ts
await page
  .locator('[data-testid="dynamic-region"]')
  .evaluateAll((els) => els.forEach((el) => el.setAttribute('data-uiverify-ignore', '')));

7. Freeze an app-driven JS animation the capturer can't reach — an infinite charting-library loop, a <canvas> spinner with no final frame. Detect the capture in the component and render the end state. @uiverify/playwright sets a UIVerify user-agent marker and a window.__UI_VERIFY__ global at record time, so a client-side branch works on its own; if the component decides this during server-side rendering (no window yet), also set a UI_VERIFY env var when you boot the app for the record run and check it:

ts
// in the component (your app code, not the test):
const isUIVerify = () =>
  (typeof process !== 'undefined' && !!process.env.UI_VERIFY) ||            // SSR / build time
  (typeof window !== 'undefined' &&
    (navigator.userAgent.includes('UIVerify') || '__UI_VERIFY__' in window)); // browser

<Chart isAnimationActive={!isUIVerify()} />

Boot the app with the env var for the capture run only — e.g. UI_VERIFY=1 npm start — so a server-rendered branch can see it; the browser markers cover client-side animation without it. This is the record-side of the same freeze the Storybook/Vitest skills apply in-browser.

Determinism the app itself owns (real-app cases a stub can't reach)

The recipes above pin variation from outside the app — routes, the clock, the DOM. The next five live where a stub can't reach: inside your components (a branch on isUIVerify(), recipe 7's helper, or the app's own CSS) or in what the test waits for. These are the ones that eat an afternoon if you fight them from the test, especially under SSR.

8. Infinite CSS animation lands on a random frame — a rotating illustration, a pulsing dot. The freeze is replay-side (see the mental model): the worker emulates prefers-reduced-motion: reduce and re-runs the archived CSS, so the animation stops only if the app honors that media query. Add it to the app's CSS — not the test:

css
@media (prefers-reduced-motion: reduce) { .rotating-logo { animation: none } }

Use animation: none, never animation-duration: 0s — 0s leaves an infinite animation on its own compositor layer and it sub-pixel-flakes (~1/100). No isUIVerify() needed here; the media query is the whole lever. (FAILED: setting reducedMotion in the test/config is a no-op at record time — the archive never bakes the computed transform, so there's nothing to freeze until replay. Don't reach for it. Also: reducedMotion is not a top-level Playwright use option anyway — it lives under use: { contextOptions: { reducedMotion: 'reduce' } } — but you don't need it at all.)

9. A <canvas> / requestAnimationFrame animation diffs every run — particles, a chart, an animated background. rrweb bakes the canvas pixels (rr_dataURL) at the instant of capture, catching a different frame each time. A media query can't reach a JS rAF loop, so branch in the component's effect:

tsx
useEffect(() => {
  if (isUIVerify()) drawOneStaticFrame();   // one deterministic frame under capture
  else startRaf();                          // the live loop for real users
}, []);

FAILED: emulating prefers-reduced-motion in the test does set matchMedia(...).matches = true in the page, but a hand-written rAF loop never reads it and keeps animating — the guard has to be in the JS.

10. A random pick made in render changes the element each run — a mascot/logo/hero image chosen by Math.random(), a shuffled list. Not a pixel shift: a different element, a large whole-element diff, every run. This is the biggest real-app time-sink. In any SSR framework (Next.js, Remix) the pick runs at server render time and the archive bakes the SSR'd choice, so a browser-side fix can't touch it. Pin the variant in the component and let real users keep the randomness:

tsx
const src = isUIVerify() ? images[0] : images[Math.floor(Math.random() * images.length)];

Because the pick is server-side, set UI_VERIFY=1 on the app server for the capture run (recipe 7) so SSR and the client agree on the fixed variant — otherwise they disagree and React throws a hydration mismatch. FAILED (do not repeat): seeding Math.random from a Playwright addInitScript fixture — it patches the browser RNG, which cannot reach a pick React already made on the server; seeded captures still rolled different sprites. (Redefining navigator.userAgent from an init script fails too — it's why the marker is set at context creation, not in-page.)

11. Even after gating the animation, a canvas/grid layout still differs — the frame is static but the square positions, particle seeds, or item order move run-to-run. The layout is drawing from the global Math.random, and seeding it globally is not enough: React and other components consume the shared sequence first, by an amount that varies with render timing, so your component gets different values each capture. Give that component its own reset-able RNG (a tiny xorshift), reset at the start of each generation, used only under capture — then its output is byte-identical across runs.

12. The capture is a skeleton / spinner, not the loaded page — the test asserted something (a URL, a button) and the auto-capture fired before the data arrived. Wait for the real content, not its container: a data row, role="tab", a specific project link — or page.waitForLoadState('networkidle'). TRAP: a generic selector like a[href^="/project/"] can match a stale link still in the DOM during a client-side transition and resolve too early, capturing the loading state. Prefer networkidle or a selector for an element that only exists once the new content has rendered.

Freezing live/dynamic data (stars, followers, tiles, listings) is recipe 2 — page.route with committed fixtures is fork-friendly where a private staging backend isn't reachable in CI. If the noise is heavy and content-driven, the higher-leverage move is often to lift those cases into Storybook or Vitest with mocked data (storybook-visual-testing / vitest-visual-testing): static data = no content churn at the source, and one component per canvas keeps the volume down.

Ops, not determinism: fork PRs, the maintainer-approval flow, the Playwright-container CI (browser-install hang), and git safe.directory are not in this skill — see /docs/open-source-and-forks. This skill is only the runnable determinism playbook.

Diagnosing a flaky diff

  1. Localized band vs whole-page shift? A whole-page shift = something changed the page height (a variant, missing lazy content, or JS layout), reflowing everything — not a style change.
  2. Whole-page → compare document.body.scrollHeight across runs. Two discrete values = a flag / third party (recipe 1). Continuous variation = JS layout (recipe 6, neutralize it).
  3. Content differs = live data (recipe 2) or the clock (recipe 3).

Then upload the archive:

bash
npx playwright test                       # archives land in uiverify-archive/
uiverify upload --static-dir uiverify-archive

Anti-patterns

  • route.abort() to block a script → can hang page readiness; use fulfill(204).
  • Hand-settling fonts / sticky animation / image decode → UI Verify re-renders and settles those; only content loading (recipe 5) is your concern.
  • Testing live prod with flags on → you're archiving a random variant.
  • Unseeded crypto/uuid/faker or live data → the archive is only as stable as what rendered into it.

Câu hỏi thường gặp

Kỹ năng AI Playwright Visual Testing làm được gì?

Make @uiverify/playwright (archive-replay) captures deterministic so real-page visual tests stop coming back "changed" without a real change (flaky diffs). Use when driving a real page — your app under test, a staging build, or live production — and the diff flakes. A symptom-to-lever checklist for the run-to-run variation you probably have - feature flags, live data, the clock, third-party widgets, and dynamic layouts. The lever is almost always "stop the variation at record time" — the archive bakes in whatever the page was.

Vì sao nên dùng Playwright Visual Testing trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Playwright Visual Testing là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Playwright Visual Testing trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/uiverify/uiverify/tree/main/packages/skills/skills/playwright-visual-testing. TypingMind đọc tệp SKILL.md và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Playwright Visual Testing?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Playwright Visual Testing với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Playwright Visual Testing với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Playwright Visual Testing có miễn phí không?

Có. Kỹ năng này được uiverify phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇