Class: Playwright::PageAssertions

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/page_assertions.rb

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) ⇒ Object

The opposite of [method: PageAssertions.toHaveTitle].



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) ⇒ Object

The opposite of [method: PageAssertions.toHaveURL].



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

#to_have_title(titleOrRegExp, timeout: nil) ⇒ Object

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"))


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

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) ⇒ Object

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"))


56
57
58
# File 'lib/playwright_api/page_assertions.rb', line 56

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