Skip to main content
Visual Testing · Stack

Visual Testing for Svelte with Playwright

Visual testing for Svelte with Playwright adds screenshot comparisons to the Playwright tests that SvelteKit projects can set up from the start. The @wopee-io/wopee.pw package sends a screenshot to Wopee.io at each point you choose, compares it with the approved baseline for your branch, and lists every difference in Wopee Commander, so layout and styling regressions in a Svelte app are reviewed rather than discovered by users.

Why visual testing Svelte with Playwright is hard

Svelte apps are small and fast, and their visual regressions are easy to miss for the same reason: there is little code between a style change and the page. Component styles are scoped with generated svelte- class hashes, so a selector copied from the DOM breaks on the next build. Built-in transitions such as transition:fade and animate:flip move content after a state change, and SvelteKit renders on the server and then hydrates, so the first paint and the interactive page can differ, especially where content depends on client-only data. Many SvelteKit projects test against a production build served by vite preview, which is the right target, but Playwright's built-in toHaveScreenshot then keeps baselines as PNG files in the repository, one per browser and OS, and every design tweak becomes an image diff in the pull request.

How Wopee.io adds visual checks to Playwright

Wopee.io keeps the SvelteKit Playwright setup and moves visual baselines and review out of the repo. Keep the webServer block that builds the app and serves it with npm run preview, add the Wopee.io reporter, and start a suite and scenario in the hooks. In the test, wait for the hydrated, finished state, for example a list that only renders on the client, and for transitions to complete, then call trackFullPage, trackViewport, or trackElement with a role-based locator instead of a svelte- class. Baselines are stored per branch and per environment label; run the same test at several widths with the viewport option and each width keeps its own baseline. Wopee Commander shows each difference next to its baseline with a highlight overlay, and ignore areas drawn there cover regions that are supposed to change. A difference leaves the test green unless you assert on the returned status, so you can start in review-only mode and enforce later. The same approach for Vue is in visual testing for Vue with Playwright, and agent-generated Svelte tests are covered in AI testing for Svelte. Setup: Playwright guide.

How to get started

  1. 1
    Create a Wopee.io project with the test framework set to Playwright and put WOPEE_API_URL, WOPEE_PROJECT_UUID, and WOPEE_API_KEY in .env.
  2. 2
    Install @wopee-io/wopee.pw and add '@wopee-io/wopee.pw/wopee-reporter' to the reporters, keeping the webServer block that builds and previews the SvelteKit app.
  3. 3
    Start a suite in beforeAll and a scenario per test in beforeEach, passing testInfo, and stop it in afterEach.
  4. 4
    Wait for hydrated content and finished transitions, then track the page or a role-based locator, passing viewport when you test several widths.
  5. 5
    Run npx playwright test, approve the first screenshots in Commander, and review unresolved steps on later runs.

Example: a Playwright test with visual checks

tests/products.visual.test.ts
import { test } from '@playwright/test';
import { Wopee } from '@wopee-io/wopee.pw';

const wopee = new Wopee();

test.beforeAll(async () => {
await wopee.startSuite(`SvelteKit visual ${new Date().toISOString().slice(0, 16)}`);
});
test.beforeEach(async ({}, testInfo) => {
await wopee.startScenario(testInfo.title, testInfo);
});
test.afterEach(async () => {
await wopee.stopScenario();
});

for (const size of [{ width: 1280, height: 800 }, { width: 390, height: 844 }]) {
test(`Products at ${size.width}px`, async ({ page }) => {
await page.setViewportSize(size);
await page.goto('/products');
// The list renders after hydration; wait for it, not the server HTML.
await page.getByRole('list', { name: 'Products' }).getByRole('listitem').first().waitFor();
await wopee.trackFullPage({
page,
stepName: 'Products',
viewport: `${size.width}x${size.height}`,
});
});
}

From manual effort to AI-assisted testing

More automation. Less maintenance. Faster review.

Manual check before release

SSR and hydration
Judged by eye
Scoped svelte- classes
Not relevant
Where baselines live
None
Several widths
Devices at hand

Playwright toHaveScreenshot

SSR and hydration
Waits written by hand
Scoped svelte- classes
Use role locators yourself
Where baselines live
PNG files in the repo, per browser and OS
Several widths
One file per project and size
Wopee.ioWopee.io
AI testing
SSR and hydration
Wait for hydrated content, then track
Scoped svelte- classes
trackElement takes any locator
Where baselines live
Wopee.io, per branch and labels
Several widths
viewport label per baseline

Add visual checks to your Playwright tests

Keep your tests, add a few track calls, and review every visual change in one place.

Frequently asked questions

A production build served with npm run preview is closer to what users get, and it is what SvelteKit's Playwright setup uses by default. Wopee.io works with either, because it compares whatever page the test opens.

Pass a viewport label to the track call, or set WOPEE_VIEWPORT for the run. The viewport label is part of the baseline identity, so each width is compared with its own approved screenshot.

Yes. By default a visual difference does not fail the test; it waits for review in Wopee Commander. When you trust the baselines, assert that the returned status is not unresolved.