Software Testing & QA (50 Qs)•Part 3: Advanced Internals, Scale & Production Quality (Senior / Lead)
Visual Regression Testing: Pixel-by-pixel diffing vs DOM snapshot testing.
senior LevelCode ExampleTesting
In Simple Words:
- DOM Snapshots (Jest): Serializes HTML string output. Fails when minor markup changes occur, but completely misses CSS layout breaks, overlapping text, or hidden elements.
- Visual Regression Testing (Playwright / Percy / Applitools):
- Captures full-page screenshots of pages or isolated components in headless Chromium/Firefox/WebKit.
- Compares screenshots against a baseline image using pixel-diffing algorithms (e.g.
pixelmatch). - Highlights visual bugs (e.g. button shifted 20px off-center, dark mode color inversion) in pull request reviews before merging.
typescript
test('landing page visual regression', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveScreenshot('landing-hero.png', { maxDiffPixelRatio: 0.01 });
});