Web-first Assertions
Assert the rendered result. Playwright retries against the page until the condition holds or the timeout is reached.
- Retry, not sleep An assertion waits for the state it asserts
- Web-first Assert what the user can perceive
- On failure The timeout names the unmet condition
An assertion waits for the state it asserts
Each assertion re-reads the page until it holds or the timeout expires. The expected outcome and the wait stay in one expression.
Timeouts and retries →// retries until the text lands, then passes
expect($page->getByRole('alert'))
->toContainText('Saved');Assert what the user can perceive
Visibility, enabled state, value, count, attribute, accessible name. The vocabulary describes the rendered page rather than the shape of the DOM behind it.
Choosing assertions →The timeout names the unmet condition
When the assertion times out, its error reports the expected condition and the observed state so you can start with the failed check.
Debugging and logging →Move from the tour to working code.
Choose the explanation, recipe, or runnable example that matches what you need next.