TOPIC 47/6017 MINNOT STARTED

Polling and retrying blocks: expect.poll and toPass

Wait for a value that is not on the page, such as an answer from the server, by checking again and again until it is right or time runs out.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: checking a pot until it boils, instead of guessing the minute. A cook who sets a timer for ten minutes may serve cold soup or burn it. A better cook looks at the pot every little while and takes it off the heat the moment it boils. If it has not boiled after a long time, the cook gives up and checks the stove.

Daily List is a to-do list app. Tom adds a task. A counts tasks and updates a number a few seconds later. Tom's test checks the number at once and sees the old one.

What it is: Playwright is a free tool, made by Microsoft, that drives real web browsers from test code. Its checks on the page, such as "this text is visible", already look again and again until they pass. This topic introduces two general retry tools, often useful for values outside ordinary locator assertions: expect.poll and toPass. The first looks again at one value. The second runs a whole block of lines again. Do not confuse them with a fixed pause such as page.waitForTimeout(10000), which always waits the full time and guesses.

Why it matters: a guesses how long a background job needs and is often wrong. Polling until the count updates waits only as long as the work takes, so the check stays both fast and steady.

He could pause for ten seconds and hope. A pause is a guess, and it is both slow and unsafe. The picture has a limit. A pot cannot boil twice, but some actions in a test can happen twice if you repeat them. This lesson shows which ones are safe to repeat.

Kept simple: this lesson covers two tools and their main options. Playwright has more settings for time limits.

(SYNTHETIC / TRAINING ONLY: Daily List, its test site and every person named here are made up.)

PLAIN WORDS · 3 in this section
playwright
a free Microsoft tool that drives a browser for tests
retry
trying the same action again after it failed
locator
a pointer telling you where to find something

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 Waiting for a value that changes by itself, such as a count or a server answer, without guessing how long it takes.

  1. Read the value
  2. Check it
  3. Wait a little
  4. Pass or give up
Look again, stop at the boil, give up on time

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The pot on the stoveThe value that changes with time
Looking at the pot every little whileA polling check
Taking it off at the first boilPassing as soon as the value matches
Giving up after a long timeThe time limit

WHERE THIS PICTURE STOPS

  • A pot cannot boil twice, but an action in a block can happen twice if the block repeats.
  • A cook knows roughly when soup boils. A test needs a limit chosen from what the product promises.
  • Looking at a pot costs nothing. Each look in a test sends a request, so very short pauses add load.

HOOK

Look again, stop at the boil, give up on time.

REMEMBER IT THIS WAY

A sequence: the real steps, in order.

Do not guess the minute: poll the number, pass when it matches, fail when the limit runs out.

What each part of the trick stands for
In the trickWhat it stands for
look againa polling check
stop at the boilpass as soon as the value matches
give upthe time limit

TELL A FRIEND

A cook looks at the pot every little while and stops at the boil, not at a guessed minute.

OFTEN MIXED UP WITH Web-first assertions: expect that keeps trying. The assertions lesson covers checks on the page that already retry. This lesson covers values that are not on the page.

Sources & standards — 3 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) · Test user-visible behaviour, keep tests isolated, and prefer web-first assertions (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.

PRACTISE AND KEEP

Sources for this topic — 3 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) · Test user-visible behaviour, keep tests isolated, and prefer web-first assertions (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.

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.