π The expect() API
Unlike Selenium where you had to write your own waits, Playwright's expect() automatically retries until the condition is met or a timeout occurs.
typescript
// Common Assertions
await expect(page.getByRole('heading')).toHaveText('Welcome Back');
await expect(page.getByLabel('Email')).toHaveValue('user@example.com');
await expect(page).toHaveURL('/dashboard');
π§ Soft Assertions
With regular assertions, the test stops on the first failure. Soft assertions let ALL checks run, then report all failures together.
typescript
await expect.soft(page.getByText('Welcome')).toBeVisible();
await expect.soft(page.locator('.stats-card')).toHaveCount(4);
πΈ Visual Comparisons (Screenshot Testing)
typescript
// Takes a screenshot on first run (baseline), then compares on next runs
await expect(page).toHaveScreenshot('homepage.png');
// Update snapshots when the UI intentionally changes:
// npx playwright test --update-snapshots