Your First Playwright Test
You'll learn: How to write a complete end-to-end test that opens your React app in a real browser, interacts with it like a user would, and verifies the result.
What an E2E Test Looks Like
Think of Playwright tests as recorded instructions for a robot user. You tell it: "Go to this page, click that button, then check if something changed." Unlike React Testing Library which tests components in isolation, Playwright opens your actual running application in a browser.
Writing Your First Test
After installing Playwright, create a test file (typically in a tests/ or e2e/ folder):
import { test, expect } from '@playwright/test';
test('clicking increment button updates counter', async ({ page }) => {
// Navigate to your running app
await page.goto('http://localhost:5173');
// Find and click a button
await page.getByRole('button', { name: /increment/i }).click();
// Assert the DOM changed as expected
await expect(page.getByText('Count: 1')).toBeVisible();
});
Notice three key parts: navigate with goto(), interact with methods like click(), and assert with expect(). The page object represents the browser tab Playwright controls.
The async/await Pattern
Every Playwright action is asynchronous because it's talking to a real browser. You must await each step. Playwright automatically waits for elements to appear and become interactive—no manual waitFor() needed.
Key Takeaway: Your first Playwright test navigates to your live app with page.goto(), interacts using accessible queries like getByRole(), and asserts DOM changes with expect().toBeVisible() or similar matchers—all following real user behavior in an actual browser.