Assertions and auto-waiting

Knowledge Videos

Short animated explainers, organised by subject.

Assertions and auto-waiting

Write the expected result with expect, why fixed sleeps make tests slow and flaky, how Playwright waits automatically, and why web-first assertions retry.

Transcript

An assertion is the expected result of your test case. In Playwright you write expect, then what you expect: to be visible, to have text, to have a U R L, to have a count.

Pages are not instant. A spinner shows, data loads, a button appears. A fixed pause, like wait for timeout five thousand, is a trap. It wastes time when the page is fast, and fails when the page is slow.

Playwright waits for you. Before every action it waits until the element is ready. And every expect keeps retrying until it passes, or until the timeout runs out.

So never read a value once and compare it. Write expect, locator, to be visible, and let Playwright retry. Your test is faster, and it fails only when the app is really wrong.

Remember: write every expected result with expect, never use fixed sleeps, and let Playwright retry for you.

More in this series