TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
Playwright / Chapter 42 of 60~18 min • Beginner
Chapter 42Playwright

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

  1. Create a status element
  2. Assert its text
  3. Try a failing expectation

Example

TypeScript
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);
});
Expected result: Both assertions pass
💡 Point to remember
Prefer await expect(locator).toBeVisible() over expect(await locator.isVisible()).toBe(true).

Practice application screenshot

Actual screenshot of the TestingDocs task manager practice application
TestingDocs practice page, captured in Chromium.

✎ Your practice task

Change Saved to Pending in the assertion.

Knowledge check

Which assertion automatically retries a locator text check?

🌐 Continue learning