| id | class-pageassertions |
|---|---|
| title | PageAssertions |
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import HTMLCard from '@site/src/components/HTMLCard';
The PageAssertions class provides assertion methods that can be used to make assertions about the Page state in the tests.
// ...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestPage {
// ...
@Test
void navigatesToLoginPage() {
// ...
page.getByText("Sign in").click();
assertThat(page).hasURL(Pattern.compile(".*/login"));
}
}<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.20pageAssertions.hasTitle
Ensures the page has the given title.
Usage
assertThat(page).hasTitle("Playwright");Arguments
-
titleOrRegExpString | Pattern Added in: v1.18#Expected title or RegExp.
-
optionsPageAssertions.HasTitleOptions(optional)
Returns
<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.20pageAssertions.hasURL
Ensures the page is navigated to the given URL.
Usage
assertThat(page).hasURL(".com");Arguments
-
urlOrRegExpString | Pattern Added in: v1.18#Expected URL string or RegExp.
-
optionsPageAssertions.HasURLOptions(optional)-
setIgnoreCaseboolean (optional) Added in: v1.44#Whether to perform case-insensitive match. setIgnoreCase option takes precedence over the corresponding regular expression parameter if specified. A provided predicate ignores this flag.
-
setTimeoutdouble (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000.
-
Returns
<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.20pageAssertions.not()
Makes the assertion check for the opposite condition.
Usage
For example, this code tests that the page URL doesn't contain "error":
assertThat(page).not().hasURL("error");Returns