English · Java
Appearance
English · Java
Appearance
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.
The following assertions will retry until the assertion passes or the assertion timeout is reached.
You can specify a custom timeout for assertions either globally or per assertion. The default timeout is 5 seconds.
import com.microsoft.playwright.assertions.PlaywrightAssertions;
PlaywrightAssertions.setDefaultAssertionTimeout(10_000);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));