TOPIC 11/6018 MINNOT STARTED

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.

  1. Name what you expect
  2. Look
  3. Look again
  4. Give up at the limit
Look until it clicks

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
Watching the kettleA web-first assertion
Looking every few secondsThe retry after a short pause
Giving up after a long timeThe expect timeout
A glance once and a walk awayA 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.

What each part of the trick stands for
In the trickWhat it stands for
Keeps lookinga web-first assertion
Single glancea 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
  1. 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.

    Locator/page web assertions re-read current state; generic value assertions do not retry. APIResponse toBeOK checks a fixed captured 2xx status once, as confirmed by the pinned 1.65 matcher implementation; broad guide grouping must not imply a request resend. Soft assertions retain failure state; poll/toPass repeat their callbacks with explicit side-effect and deadline considerations. · Checked 2026-11-06

    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.

  2. 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)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    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).

  3. 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.

    Says Playwright runs actionability checks (visible, stable, enabled, receives events) before an action and fails with a timeout error if they do not pass in time. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-11-06

    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.

  4. 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.

    Describes the toBeOK assertion on a response, which passes when the status code is in the 200 to 299 range, and its negated form. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    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.

  5. 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.

    toBeOK reads a captured APIResponse status once, accepts 200–299, and does not resend the request; toPass retries its callback. · Checked 2026-11-06

    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
  1. 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.

    Locator/page web assertions re-read current state; generic value assertions do not retry. APIResponse toBeOK checks a fixed captured 2xx status once, as confirmed by the pinned 1.65 matcher implementation; broad guide grouping must not imply a request resend. Soft assertions retain failure state; poll/toPass repeat their callbacks with explicit side-effect and deadline considerations. · Checked 2026-11-06

    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.

  2. 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)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    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).

  3. 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.

    Says Playwright runs actionability checks (visible, stable, enabled, receives events) before an action and fails with a timeout error if they do not pass in time. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-11-06

    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.

  4. 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.

    Shows an absence check passing before delayed work starts, using a Cypress loading example. · Checked 2026-10-22

    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.

  5. 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.

    Describes the toBeOK assertion on a response, which passes when the status code is in the 200 to 299 range, and its negated form. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    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.

  6. 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.

    toBeOK reads a captured APIResponse status once, accepts 200–299, and does not resend the request; toPass retries its callback. · Checked 2026-11-06

    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.