Skip to main content

Command Palette

Search for a command to run...

Visual Testing with Playwright

Updated
2 min readView as Markdown
Visual Testing with Playwright
H

QA Engineer | Selenium, Playwright, Postman, JMeter | API/UI Testing | Manual & Automation | MERN Stack | ISTQB Trainee | QA Blogger

When I started my QA internship, I thought testing was only about checking if buttons click or APIs respond. But then I learned about visual testing, and wow — it completely changed how I think about testing web apps.

Functional tests tell us “does it work?”
Visual tests tell us “does it look right?”

And trust me — both matter!

Why Visual Testing is Important

Imagine this scenario:

  • Dev changes some CSS

  • Button moves a little

  • Text overlaps

Functional tests might still pass. Everything works. ✅

But visually, the page looks broken. ❌

This is exactly why visual testing catches problems that normal tests miss.

Playwright Makes It Easy

Playwright can automatically take screenshots and compare them to a baseline.

Basic idea:

  1. Take a screenshot of the page or component → baseline

  2. Next test run → take a new screenshot

  3. Compare new screenshot with baseline

  4. If something changed → test fails

Simple code example:

import { test, expect } from '@playwright/test';

test('Home page visual test', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot();
});

How We Use Visual Testing in Real Projects

Step 1: Create Baseline Screenshots

After UI approval, QA creates baseline screenshots. These images are the “truth” for how the app should look.

Step 2: Developers Push Changes

CSS updates, layout tweaks, font changes — all these can happen without breaking functionality.

Step 3: CI/CD Runs Visual Tests

Every time code is pushed:

  • Playwright compares new screenshots with baselines

  • Shows differences (if any)

  • QA reviews the changes

Step 4: QA Reviews

  • If it’s a bug, report it

  • If it’s an intended change, update baseline:

Page-Level vs Component-Level Testing

Page-Level Testing

  • Captures full page

  • Good for login page, checkout page, dashboards

  • But sensitive — even small dynamic elements can fail tests

Component-Level Testing

  • Focus on one element, like a button or header

  • More stable and faster

The coolest part? Running visual tests automatically in CI/CD pipelines.

Every time someone pushed code:

  • Playwright captured new screenshots

  • Compared them to baselines

  • Highlighted differences automatically

No more manually checking pages — huge time saver. ⏱️

For small projects, Playwright is enough. But bigger projects often use Percy:

  • AI-powered screenshot comparisons

  • Cloud storage for baselines

  • PR-level visual review

  • Cross-browser testing

Percy helps avoid false positives and keeps everything organized.

QA Debug Diary

Part 7 of 8

QA Debug Diary is your go-to series for software testing, bug hunting, and debugging tips. Whether you're a QA engineer, developer, or tech enthusiast, this series helps you catch bugs, improve testing, and build better software.

Up next

My First 6 Months in Quality Assurance

This New Year feels different.Not because of celebrations but because when I look back at the last six months, I barely recognize the person I was when I started my internship at AVLYON Back then, I w

More from this blog

How to Begin API Automation: From Postman to Newman

අද මම කතා කරන්න යන්නේ ජනප්‍රිය API Testing tool එකක් වෙන Postman ගැන.හැබැයි අද මගේ Main Topic එක Postman ගැන නෙවෙයි — ඒකේ සහෝදරයා, කියලා කියන්න පුළුවන් Newman ගැන. Postman සහ Newman දෙන්න අතර වෙනස හිතන්න මෙහෙම Postman = Manual testing tool Newman =...

Oct 13, 20254 min read
How to Begin API Automation: From Postman to Newman

📌 Schema Validation කියන්නේ මොකක්ද?

Schema කියන්නේ basically blueprint එකක් for your data.ඒ කියන්නේ, API එකෙන් එන data එකේ ආකාරය, format එක, මොකක්ද කියලා define කරන එක.API එකක් test කරනකොට, data එක පමණක් නොව, එය data එන structure එකත් බලන්න ඕන. මේකට Schema Validation කියල කියනවා 🔎 උදා...

Sep 10, 20252 min read
📌 Schema Validation කියන්නේ මොකක්ද?

Dev Diaries By Hasanka

17 posts

QA Engineer | Selenium, Playwright, Postman, JMeter | API/UI Testing | Manual & Automation | MERN Stack | ISTQB Trainee | QA Blogger