Skip to main content
Visual Testing · Stack

Visual Testing for Angular with Playwright

Visual testing for Angular with Playwright means taking screenshots at chosen points in your Playwright tests and comparing them with approved baselines, so a broken Material theme, a shifted layout, or a dialog that renders off-screen fails review even when every functional assertion passes. With the @wopee-io/wopee.pw package, each trackFullPage, trackViewport, or trackElement call sends the screenshot to Wopee.io, which compares it with the baseline for your branch and puts every difference up for approval in Wopee Commander.

Why visual testing Angular with Playwright is hard

Angular apps are easy to screenshot and hard to screenshot reliably. Rendering finishes a tick after the event that caused it, Angular Material animates ripples, expansion panels, and dialogs, and web fonts such as Roboto and Material Icons load after the first paint, so a screenshot taken too early captures a half-drawn page. Material dialogs, menus, and date pickers render in the CDK overlay container at the end of the document body, outside the component that opened them, so an element screenshot of the component misses the overlay entirely. Playwright's built-in toHaveScreenshot solves the comparison but stores baseline PNG files in the repository, one per browser and operating system, so baselines made on a Mac do not match a Linux CI runner, a theme change produces a pull request full of binary images, and reviewing a diff means opening each HTML report.

How Wopee.io adds visual checks to Playwright

Wopee.io keeps your Playwright tests as they are and moves the baselines and the review out of the repository. You add the Wopee.io reporter to playwright.config.ts, start a suite and a scenario in the test hooks, and call trackFullPage where the page is settled, for example after a heading or table you expect is visible. For Material dialogs and menus, use trackFullPage or trackViewport rather than trackElement on the host component, because the overlay lives outside it. Baselines are stored in Wopee.io per branch and per browser, OS, and viewport label, and WOPEE_BASELINE_BRANCH_NAME lets a feature branch compare against master until it has its own. Differences show up in Commander with a highlight overlay; you approve an intended change or reject a bug, and ignore areas drawn there keep timestamps and live values out of the comparison. A difference does not fail the test unless you check the returned status. If you want the tests themselves written for you, the Wopee.io agent can also generate Playwright tests from your running Angular app, see AI testing for Angular. Setup details are in the Playwright guide.

How to get started

  1. 1
    Create a Wopee.io project with the test framework set to Playwright and copy WOPEE_API_URL, WOPEE_PROJECT_UUID, and a new WOPEE_API_KEY into a .env file.
  2. 2
    Install the package with npm i -D @wopee-io/wopee.pw and add '@wopee-io/wopee.pw/wopee-reporter' to the reporter list in playwright.config.ts, with baseURL pointing at ng serve (http://localhost:4200) or your preview build.
  3. 3
    In the spec, start a suite in beforeAll, start a scenario with the test title in beforeEach, and stop it in afterEach.
  4. 4
    Call wopee.trackFullPage after the content you want to capture is visible; for Material dialogs and menus, capture the full page or the viewport.
  5. 5
    Run npx playwright test, approve the first screenshots as baselines in Commander, and on later runs approve or reject each unresolved step.

Example: a Playwright test with visual checks

e2e/settings.visual.spec.ts
import { test } from '@playwright/test';
import { Wopee } from '@wopee-io/wopee.pw';

const wopee = new Wopee();

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

test('Settings and edit profile dialog', async ({ page }) => {
await page.goto('/settings');
await page.getByRole('heading', { name: 'Settings' }).waitFor();
await wopee.trackFullPage({ page, stepName: 'Settings page' });

await page.getByRole('button', { name: 'Edit profile' }).click();
// Material dialogs render in the CDK overlay container, outside the component.
await page.getByRole('dialog').waitFor();
await wopee.trackViewport({ page, stepName: 'Edit profile dialog' });
});

From manual effort to AI-assisted testing

More automation. Less maintenance. Faster review.

Manual check before release

Where baselines live
In the tester's memory
Material overlays
Checked if someone opens them
Review of differences
By eye
Branches
None

Playwright toHaveScreenshot

Where baselines live
PNG files in the repo, per browser and OS
Material overlays
Full-page or viewport snapshots
Review of differences
HTML report per run
Branches
Whatever is committed on the branch
Wopee.ioWopee.io
AI testing
Where baselines live
Wopee.io, per branch and environment label
Material overlays
trackFullPage or trackViewport
Review of differences
Approve or reject per step in Commander
Branches
Per branch, with a baseline branch fallback

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

No. You add the Wopee.io reporter to the config, a few lines in the test hooks to start and stop the suite and scenario, and a track call at each point you want to check. Your locators and assertions stay as they are.

Not by default: the test passes and the step waits for review in Wopee Commander. To fail the test as well, check the status the track call returns, for example expect(result?.status).not.toBe('unresolved').

Wait for the element you want to capture before each track call, and consider providing the no-op animations module in the build you test against. Ignore areas drawn in Commander cover regions that change on purpose, such as timestamps.