Class: Playwright::PageAssertions

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/page_assertions.rb,
sig/playwright.rbs

Overview

The PageAssertions class provides assertion methods that can be used to make assertions about the Page state in the tests.

import re
from playwright.sync_api import Page, expect

def test_navigates_to_login_page(page: Page) -> None:
    # ..
    page.get_by_text("Sign in").click()
    expect(page).to_have_url(re.compile(r".*/login"))

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#not_to_have_title(titleOrRegExp, timeout: nil) ⇒ void

This method returns an undefined value.

The opposite of [method: PageAssertions.toHaveTitle].

Parameters:

  • titleOrRegExp (String, Regexp)
  • timeout: (Float) (defaults to: nil)


18
19
20
# File 'lib/playwright_api/page_assertions.rb', line 18

def not_to_have_title(titleOrRegExp, timeout: nil)
  wrap_impl(@impl.not_to_have_title(unwrap_impl(titleOrRegExp), timeout: unwrap_impl(timeout)))
end

#not_to_have_url(urlOrRegExp, ignoreCase: nil, timeout: nil) ⇒ void

This method returns an undefined value.

The opposite of [method: PageAssertions.toHaveURL].

Parameters:

  • urlOrRegExp (String, Regexp)
  • ignoreCase: (Boolean) (defaults to: nil)
  • timeout: (Float) (defaults to: nil)


24
25
26
# File 'lib/playwright_api/page_assertions.rb', line 24

def not_to_have_url(urlOrRegExp, ignoreCase: nil, timeout: nil)
  wrap_impl(@impl.not_to_have_url(unwrap_impl(urlOrRegExp), ignoreCase: unwrap_impl(ignoreCase), timeout: unwrap_impl(timeout)))
end

#not_to_match_aria_snapshot(expected, timeout: nil) ⇒ void

This method returns an undefined value.

The opposite of [method: PageAssertions.toMatchAriaSnapshot].

Parameters:

  • expected (String)
  • timeout: (Float) (defaults to: nil)


46
47
48
# File 'lib/playwright_api/page_assertions.rb', line 46

def not_to_match_aria_snapshot(expected, timeout: nil)
  wrap_impl(@impl.not_to_match_aria_snapshot(unwrap_impl(expected), timeout: unwrap_impl(timeout)))
end

#to_have_title(titleOrRegExp, timeout: nil) ⇒ void

This method returns an undefined value.

Ensures the page has the given title.

Usage

import re
from playwright.sync_api import expect

# ...
expect(page).to_have_title(re.compile(r".*checkout"))

Parameters:

  • titleOrRegExp (String, Regexp)
  • timeout: (Float) (defaults to: nil)


62
63
64
# File 'lib/playwright_api/page_assertions.rb', line 62

def to_have_title(titleOrRegExp, timeout: nil)
  wrap_impl(@impl.to_have_title(unwrap_impl(titleOrRegExp), timeout: unwrap_impl(timeout)))
end

#to_have_url(urlOrRegExp, ignoreCase: nil, timeout: nil) ⇒ void

This method returns an undefined value.

Ensures the page is navigated to the given URL.

Usage

import re
from playwright.sync_api import expect

# ...
expect(page).to_have_url(re.compile(".*checkout"))

Parameters:

  • urlOrRegExp (String, Regexp)
  • ignoreCase: (Boolean) (defaults to: nil)
  • timeout: (Float) (defaults to: nil)


78
79
80
# File 'lib/playwright_api/page_assertions.rb', line 78

def to_have_url(urlOrRegExp, ignoreCase: nil, timeout: nil)
  wrap_impl(@impl.to_have_url(unwrap_impl(urlOrRegExp), ignoreCase: unwrap_impl(ignoreCase), timeout: unwrap_impl(timeout)))
end

#to_match_aria_snapshot(expected, timeout: nil) ⇒ void

This method returns an undefined value.

Asserts that the page body matches the given accessibility snapshot.

Usage

page.goto("https://demo.playwright.dev/todomvc/")
expect(page).to_match_aria_snapshot('''
  - heading "todos"
  - textbox "What needs to be done?"
''')

Parameters:

  • expected (String)
  • timeout: (Float) (defaults to: nil)


40
41
42
# File 'lib/playwright_api/page_assertions.rb', line 40

def to_match_aria_snapshot(expected, timeout: nil)
  wrap_impl(@impl.to_match_aria_snapshot(unwrap_impl(expected), timeout: unwrap_impl(timeout)))
end