Skip to main content
Version: 1.18

PlaywrightAssertions

The PlaywrightAssertions class provides convenience methods for creating assertions that will wait until the expected condition is met.

Consider the following example:

...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

public class TestExample {
...
@Test
void statusBecomesSubmitted() {
...
page.click("#submit-button");
assertThat(page.locator(".status")).hasText("Submitted");
}
}

Playwright will be re-testing the node with the selector .status until fetched Node has the "Submitted" text. It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is reached. You can pass this timeout as an option.

By default, the timeout for assertions is set to 5 seconds.

PlaywrightAssertions.assertThat(response)

Creates a APIResponseAssertions object for the given APIResponse.

PlaywrightAssertions.assertThat(response).isOK();

PlaywrightAssertions.assertThat(locator)

Creates a LocatorAssertions object for the given Locator.

PlaywrightAssertions.assertThat(locator).isVisible();

PlaywrightAssertions.assertThat(page)

Creates a PageAssertions object for the given Page.

PlaywrightAssertions.assertThat(page).hasTitle("News");