DEV Community

Arhan Khan
Arhan Khan

Posted on

Playwright for Beginners: Test Your Web App in Every Browser, Automatically

Playwright is a browser automation tool from Microsoft that lets you test your web app in Chromium, Firefox, and WebKit — all with one API. If you have ever shipped a bug that only appeared in Safari, Playwright is the tool that would have caught it. It is the modern answer to the question: how do I know my app actually works in a real browser?

The idea is simple. You write a test in JavaScript, TypeScript, Python, or C#, and Playwright opens a real browser, clicks buttons, fills forms, and checks what appears on the page. Unlike older tools, it waits for elements automatically — no more flaky sleeps and timeouts. If an element is not ready yet, Playwright waits for it.

A first Playwright test looks like this:

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

test('homepage has a title', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveTitle(/Example/);
  await page.getByRole('link', { name: 'More information' }).click();
  await expect(page).toHaveURL(/iana.org/);
});
Enter fullscreen mode Exit fullscreen mode

That test runs in all three browsers with one command: npx playwright test. Add --project=firefox or --project=webkit and you are testing in a different engine. Playwright also gives you screenshots on failure, video recordings, and a trace viewer that lets you step through a failed test click by click — the single best debugging experience in browser testing.

Playwright is not only for testing. It is also used for scraping, for automating repetitive browser work, and for taking screenshots of pages. But testing is where it shines, because its auto-waiting and its locator system — getByRole, getByText, getByLabel — push you toward tests that describe what the user sees, not fragile CSS selectors.

The limits are honest. Playwright tests are slower than unit tests, because they run a real browser. They need a browser installed, which can be heavy in CI. And if your app is a simple static site with no interaction, Playwright is overkill — a linter and a manual check will do. But for any app where a broken button costs you users, it pays for itself fast.

Start today with one step: run npm init playwright@latest in a small project, write the title test above against your own homepage, and run it. When it passes in three browsers, you will never want to test by clicking around manually again.

Top comments (0)