Skip to content

Latest commit

 

History

History
182 lines (142 loc) · 9.1 KB

File metadata and controls

182 lines (142 loc) · 9.1 KB
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"));
  }
}

Methods

hasTitle {#page-assertions-to-have-title}

<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

  • titleOrRegExp String | Pattern Added in: v1.18#

    Expected title or RegExp.

  • options PageAssertions.HasTitleOptions (optional)

    • setTimeout double (optional) Added in: v1.18#

      Time to retry the assertion for in milliseconds. Defaults to 5000.

Returns


hasURL {#page-assertions-to-have-url}

<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

  • urlOrRegExp String | Pattern Added in: v1.18#

    Expected URL string or RegExp.

  • options PageAssertions.HasURLOptions (optional)

    • setIgnoreCase boolean (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.

    • setTimeout double (optional) Added in: v1.18#

      Time to retry the assertion for in milliseconds. Defaults to 5000.

Returns


Properties

not() {#page-assertions-not}

<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