Chapter 42: Web-first assertions
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Web-first assertions
Assertions compare actual application state against expectations. Locator assertions such as toBeVisible and toHaveText retry until they pass or time out. Generic value assertions check a value immediately. Await asynchronous locator assertions.
How it works
Step-by-step walkthrough
- Create a status element
- Assert its text
- Try a failing expectation
Example
import { test, expect } from '@playwright/test';
test('chapter 42 practice', async ({ page }) => {
await page.setContent('<p role="status">Saved</p>');
await expect(page.getByRole('status')).toHaveText('Saved');
expect(2 + 2).toBe(4);
});Prefer await expect(locator).toBeVisible() over expect(await locator.isVisible()).toBe(true).
Practice application screenshot
✎ Your practice task
Change Saved to Pending in the assertion.
Knowledge check
Which assertion automatically retries a locator text check?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.