Interface PageAssertions

All Known Implementing Classes:
PageAssertionsImpl

public interface PageAssertions
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"));
   }
 }
 
  • Method Details

    • not

      Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't contain "error":
      
       assertThat(page).not().hasURL("error");
       
      Since:
      v1.20
    • hasTitle

      default void hasTitle(String titleOrRegExp)
      Ensures the page has the given title.

      **Usage**

      
       assertThat(page).hasTitle("Playwright");
       
      Parameters:
      titleOrRegExp - Expected title or RegExp.
      Since:
      v1.20
    • hasTitle

      void hasTitle(String titleOrRegExp, PageAssertions.HasTitleOptions options)
      Ensures the page has the given title.

      **Usage**

      
       assertThat(page).hasTitle("Playwright");
       
      Parameters:
      titleOrRegExp - Expected title or RegExp.
      Since:
      v1.20
    • hasTitle

      default void hasTitle(Pattern titleOrRegExp)
      Ensures the page has the given title.

      **Usage**

      
       assertThat(page).hasTitle("Playwright");
       
      Parameters:
      titleOrRegExp - Expected title or RegExp.
      Since:
      v1.20
    • hasTitle

      void hasTitle(Pattern titleOrRegExp, PageAssertions.HasTitleOptions options)
      Ensures the page has the given title.

      **Usage**

      
       assertThat(page).hasTitle("Playwright");
       
      Parameters:
      titleOrRegExp - Expected title or RegExp.
      Since:
      v1.20
    • hasURL

      default void hasURL(String urlOrRegExp)
      Ensures the page is navigated to the given URL.

      **Usage**

      
       assertThat(page).hasURL(".com");
       
      Parameters:
      urlOrRegExp - Expected URL string or RegExp.
      Since:
      v1.20
    • hasURL

      void hasURL(String urlOrRegExp, PageAssertions.HasURLOptions options)
      Ensures the page is navigated to the given URL.

      **Usage**

      
       assertThat(page).hasURL(".com");
       
      Parameters:
      urlOrRegExp - Expected URL string or RegExp.
      Since:
      v1.20
    • hasURL

      default void hasURL(Pattern urlOrRegExp)
      Ensures the page is navigated to the given URL.

      **Usage**

      
       assertThat(page).hasURL(".com");
       
      Parameters:
      urlOrRegExp - Expected URL string or RegExp.
      Since:
      v1.20
    • hasURL

      void hasURL(Pattern urlOrRegExp, PageAssertions.HasURLOptions options)
      Ensures the page is navigated to the given URL.

      **Usage**

      
       assertThat(page).hasURL(".com");
       
      Parameters:
      urlOrRegExp - Expected URL string or RegExp.
      Since:
      v1.20