Skip to main content
expect dispatches on its argument; expect.poll re-reads a value until a matcher holds.
An engine-contributed fixture may carry its own expectation surface (Expectable<E>): expect(web) returns the WebExpectation the playwright engine attaches. Anything that is neither a runner locator nor such a fixture falls through to ValueExpectation<T>, including a promise. Await the value first. .not is a getter that returns a new expectation with inverted polarity, on all three kinds. Locator strictness: except for toHaveCount, a positive matcher requires exactly one match; zero matches keep polling until the timeout, and multiple matches fail immediately with LOCATOR_AMBIGUOUS. toBeHidden and negated visibility accept zero matches. Text comparison is normalized: leading and trailing whitespace is trimmed and each run of whitespace collapses to one space. A TextMatch string matches exactly; a RegExp uses its own source and flags.

Locator matchers

web matchers

Contributed by @e2edev/playwright; the type is exported from that package. Every matcher call is a recorded expect.<matcher> assertion step.

Value matchers

Synchronous, no options, no timeout. For a value the app is still writing, see Polling a value.

Polling a value

expect.poll(read) re-reads a value until a value matcher passes. An agent step returns once the model has observed the app, which can be before the write it triggered has landed; poll the read that proves the write instead of sleeping.
Every value matcher is there under the same name and parameters, returning a promise; .not flips the check. Each sample calls read, then runs the matcher on the result. A matcher failure or a read that throws is one failing sample and polling continues. A read that hangs is cut at the deadline, so one stuck request cannot stretch the wait. The poll runs on the attempt’s budget. When the attempt is cancelled or times out, the loop and any read in flight stop at once with CANCELLED, so a timed-out test never keeps reading through teardown. timeout must be a finite number of milliseconds, 0 or more, and interval a finite number above 0; anything else is INVALID_CONFIG when expect.poll is called, before the first read. At the deadline it throws ASSERTION_FAILED naming the matcher, then message when given, then the last sample: the last matcher failure, the last read error, or no read completed.
Unlike a locator matcher, expect.poll is not recorded as a report step: it touches no fixture, so a timeout surfaces only as the test’s failure.

Writing tests

screen and Locator

app and web

Errors