Interface PlaywrightAssertions
public interface PlaywrightAssertions
Playwright gives you Web-First Assertions with convenience methods for creating assertions that will wait and retry
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.locator("#submit-button").click();
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.
-
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic APIResponseAssertionsassertThat(APIResponse response) Creates aAPIResponseAssertionsobject for the givenAPIResponse.static LocatorAssertionsassertThat(Locator locator) Creates aLocatorAssertionsobject for the givenLocator.static PageAssertionsassertThat(Page page) Creates aPageAssertionsobject for the givenPage.static voidsetDefaultAssertionTimeout(double milliseconds) Changes default timeout for Playwright assertions from 5 seconds to the specified value.
-
Method Details
-
assertThat
Creates aAPIResponseAssertionsobject for the givenAPIResponse.**Usage**
PlaywrightAssertions.assertThat(response).isOK();- Parameters:
response-APIResponseobject to use for assertions.- Since:
- v1.18
-
assertThat
Creates aLocatorAssertionsobject for the givenLocator.**Usage**
PlaywrightAssertions.assertThat(locator).isVisible();- Parameters:
locator-Locatorobject to use for assertions.- Since:
- v1.18
-
assertThat
Creates aPageAssertionsobject for the givenPage.**Usage**
PlaywrightAssertions.assertThat(page).hasTitle("News");- Parameters:
page-Pageobject to use for assertions.- Since:
- v1.18
-
setDefaultAssertionTimeout
static void setDefaultAssertionTimeout(double milliseconds) Changes default timeout for Playwright assertions from 5 seconds to the specified value.**Usage**
PlaywrightAssertions.setDefaultAssertionTimeout(30_000);- Parameters:
timeout- Timeout in milliseconds.- Since:
- v1.25
-