End-to-end and component testing · mid
Network mocking, visual comparisons and ARIA snapshots in Playwright
Playwright can intercept requests with page.route (fulfil, abort or modify them, or replay a HAR), compare screenshots against stored baselines with toHaveScreenshot, and compare the accessibility tree with ARIA snapshots, which lets E2E tests be fast and deterministic where it matters.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- page.route('**/api/products*', (route) => route.fulfill({ json: [...] })) mocks a response; route.abort() simulates failure; route.fetch() then modify for partial changes.
- Mock third parties you don't control (payments sandbox, maps, analytics) and slow/unstable dependencies; keep a few tests against the real backend for true end-to-end confidence.
- HAR recording and routeFromHAR replay real traffic captured once.
- toHaveScreenshot: the first run saves a baseline per browser and OS; later runs diff pixels with threshold / maxDiffPixels; update with --update-snapshots. Rendering differs by OS, so generate baselines in the same Docker image as CI. Hide or mask dynamic content (dates, ads, carousels).
- ARIA snapshots (toMatchAriaSnapshot) compare roles and names; they catch accessibility regressions and are less brittle than DOM snapshots.
- The Clock API (page.clock) controls time in the page for countdowns and session timeouts.
The red pen
Common traps: mistake → fix
Mistake: "Mock every request in E2E tests"
Fix: then it's an integration test in a browser; keep some unmocked critical paths.
Mistake: "Screenshot baselines from a Mac work in Linux CI"
Fix: fonts and anti-aliasing differ; baselines are per platform.
Easy to hard
Questions interviewers ask, easy to hard
- How do you mock network calls in Playwright?
- How would you set up visual regression tests for a design system?
- What makes visual tests flaky and how do you control it?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.