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.
- Read the value
- Check it
- Wait a little
- Pass or give up
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The pot on the stove | The value that changes with time |
| Looking at the pot every little while | A polling check |
| Taking it off at the first boil | Passing as soon as the value matches |
| Giving up after a long time | The 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.
| In the trick | What it stands for |
|---|---|
| look again | a polling check |
| stop at the boil | pass as soon as the value matches |
| give up | the 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
- 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) · Test user-visible behaviour, keep tests isolated, and prefer web-first assertions (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.
PRACTISE AND KEEP
Sources for this topic — 3 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) · Test user-visible behaviour, keep tests isolated, and prefer web-first assertions (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.
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.