Assertions
Introduction
Playwright includes web-specific assertions that automatically retry until the expected condition is met. Consider the following example:
assertThat(page.getByTestId("status")).hasText("Submitted");
Playwright will re-test the element with the test ID of status until it has the "Submitted" text. It will re-fetch the element and check it repeatedly until the condition is met or the timeout is reached.
By default, the timeout for assertions is 5 seconds.
Auto-retrying assertions
The following assertions will retry until the assertion passes or the assertion timeout is reached.
Setting a custom timeout
You can specify a custom timeout for assertions either globally or per assertion. The default timeout is 5 seconds.
Global timeout
import com.microsoft.playwright.assertions.PlaywrightAssertions;
PlaywrightAssertions.setDefaultAssertionTimeout(10_000);
Per assertion timeout
import com.microsoft.playwright.assertions.LocatorAssertions;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
assertThat(page.getByText("Name")).isVisible(
new LocatorAssertions.IsVisibleOptions().setTimeout(10_000));