Web-first assertions: expect that keeps trying
Check the page with an assertion that keeps trying until it is true or time runs out, and keep one-shot checks for values you already hold.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: watching a kettle until it clicks off. You do not glance once and walk away. You look again until the kettle clicks, or until you have waited long enough to know it will not.
Daily List is a to-do list app. When Lily adds a task, a Saved message appears. It may take a blink, or half a second. Tom's test must check that the message shows. A single glance can land too early and say the message is missing.
What it is: Playwright is a library that drives a real browser. This slice is the , that keeps looking at the page until it is true or time runs out. An assertion matcher is the name of the check, such as toBeVisible. The nearest neighbour is a non-retrying assertion, which looks once at a value you already hold. Selenium's explicit waits are the older way to retry a condition by hand.
Why it matters: Pages are not instant. A one-glance check fails on a slow and passes on Tom's laptop. A web-first assertion waits for the Saved message Lily would actually see, so the result matches the product.
A kettle clicks off by itself. A page does not announce that it is finished. The test has to say what it is waiting to see.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are made up.)
PLAIN WORDS · 4 in this section
- playwright
- a free Microsoft tool that drives a browser for tests
- retrying
- trying the same payment or request again
- selenium
- A free tool that drives a web browser for checks.
- retry
- trying the same action again after it failed
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Checking the page with that looks again until it is right.
- Name what you expect
- Look
- Look again
- Give up at the limit
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| Watching the kettle | A web-first assertion |
| Looking every few seconds | The retry after a short pause |
| Giving up after a long time | The expect timeout |
| A glance once and a walk away | A check that looks only once |
WHERE THIS PICTURE STOPS
- A kettle clicks off by itself. A page gives no signal, so the test must say what to wait for.
- You can see the kettle. Playwright asks the browser about the element.
- You choose how long to watch. A test uses a set limit.
HOOK
Look until it clicks.
REMEMBER IT THIS WAY
A rule of thumb: if you see this, think that.
If a message appears after a blink, use that keeps looking, not a single glance.
| In the trick | What it stands for |
|---|---|
| Keeps looking | a web-first assertion |
| Single glance | a check that looks only once |
A check that keeps looking still gives up after the expect timeout.
TELL A FRIEND
Watching a kettle until it clicks off instead of glancing once.
OFTEN MIXED UP WITH Auto-waiting: what Playwright checks before it acts. The earlier lesson waits for an element to be ready before an action. This lesson keeps checking page content until it is right.
Sources & standards — 5 sources
- Market practice
Assertions (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Use web-first assertions that wait and retry, and avoid checks that run once on a value read from the page (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).
- Market practice
Auto-waiting (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
APIResponseAssertions (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: toBeOK fixed response status. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: toBeOK fixed response status. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Playwright 1.65.0 response matcher implementation ↗ — Microsoft (Playwright) · Playwright v1.65.0 pinned source: toBeOK reads a captured APIResponse status once, accepts 200–299, and does not resend the request; toPass retries its callback. Inspected 6 November 2026; source contract, not an upstream execution claim.
Actual pinned source section inspected during the completed v45 analysis. Framework source is Apache-2.0, distinct from the documentation CC BY 4.0 licence. Upstream tests were not executed.
PRACTISE AND KEEP
Sources for this topic — 6 sources
- Market practice
Assertions (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Use web-first assertions that wait and retry, and avoid checks that run once on a value read from the page (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).
- Market practice
Auto-waiting (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Be Careful With Negative Assertions (Gleb Bahmutov) ↗ — Gleb Bahmutov · Opened body: delayed loading example shows a hidden check passing before work starts; checking visible then hidden needs control of fast changes. Cypress example; Playwright application is editorial inference.
Relevant article body opened and read. This is a named practitioner demonstration in Cypress, not Playwright documentation or a general standard. The lesson applies the logical limit of absence evidence to a synthetic Playwright example; no code was run.
- Market practice
APIResponseAssertions (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: toBeOK fixed response status. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: toBeOK fixed response status. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Playwright 1.65.0 response matcher implementation ↗ — Microsoft (Playwright) · Playwright v1.65.0 pinned source: toBeOK reads a captured APIResponse status once, accepts 200–299, and does not resend the request; toPass retries its callback. Inspected 6 November 2026; source contract, not an upstream execution claim.
Actual pinned source section inspected during the completed v45 analysis. Framework source is Apache-2.0, distinct from the documentation CC BY 4.0 licence. Upstream tests were not executed.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.