poll a slow-updating backend value inside a playwright assertion using expect.poll instead of a manual retry loop

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. wrap the value-producing call (e.g. an API request or DB check) in an async function passed to expect.poll(async () => { ... })
  2. chain a standard matcher such as .toBe(200) or .toEqual(expected) onto the poll call to define the success condition
  3. optionally pass { timeout: ms } and a custom message as the second argument to expect.poll to control how long polling continues and improve failure output
  4. run the test and confirm Playwright retries the function on the built-in interval schedule (default roughly 100/250/500/1000ms) until the matcher passes or the timeout elapses
  5. combine with expect.soft(...).poll(...) if the assertion should not immediately abort the test on failure

Known gotchas

Related routes

assert on websocket frames in a playwright test using page.waitforevent('websocket')
playwright.dev · 5 steps · unrated
Control timers and fake the system clock in Playwright tests using page.clock
playwright.dev · 5 steps · unrated
Make headless-browser file downloads deterministic by awaiting the download event/promise instead of polling the filesystem
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans