Page & Element Assertions in Playwright
From the Playwright cheat sheet ยท Assertions ยท verified Jul 2026
Page & Element Assertions
Assert on page state, element visibility, text content, and attributes
typescript
// Page assertions
await expect(page).toHaveTitle(/Dashboard/);
await expect(page).toHaveURL('/dashboard');
// Visibility
await expect(page.getByText('Welcome')).toBeVisible();
await expect(page.getByText('Loading')).toBeHidden();
// Text content
await expect(page.locator('h1')).toHaveText('Hello');
await expect(page.locator('p')).toContainText('world');๐ก All expect assertions auto-retry until the condition is met or timeout expires
โก Use soft assertions when you want to collect all failures without stopping the test
๐ Screenshot assertions auto-generate golden files on first run โ commit them to git
๐ข Default assertion timeout is 5s โ override per-assertion with { timeout: ms }
assertionsexpect