Software Testing & QA (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
Visual Regression Testing: Pixelmatch, Percy, and Tolerance Thresholds.
senior LevelCode ExampleTestingSystem Design
In Simple Words: Functional tests verify that text exists, but miss layout bugs (e.g. CSS bug hiding a checkout button behind an image or breaking mobile typography).
- Visual Regression Testing: Takes screenshot snapshots of rendered pages and computes a pixel-by-pixel diff against a baseline image:
typescript
test('landing page visually matches baseline', async ({ page }) => { await page.goto('/'); await expect(page).toHaveScreenshot('landing-page.png', { maxDiffPixels: 50, threshold: 0.2 // Anti-aliasing tolerance }); }); - Masking Dynamic Elements: Always mask dynamic content (timestamps, avatar pictures, advertisements) to avoid false diff alerts.