File: class-pageassertions.md | Updated: 11/18/2025
On this page
The PageAssertions class provides assertion methods that can be used to make assertions about the Page state in the tests.
Sync
Async
import refrom playwright.sync_api import Page, expectdef test_navigates_to_login_page(page: Page) -> None: # .. page.get_by_text("Sign in").click() expect(page).to_have_url(re.compile(r".*/login"))
import refrom playwright.async_api import Page, expectasync def test_navigates_to_login_page(page: Page) -> None: # .. await page.get_by_text("Sign in").click() await expect(page).to_have_url(re.compile(r".*/login"))
Methods
Added in: v1.20 pageAssertions.not_to_have_title
The opposite of expect(page).to_have_title() .
Usage
expect(page).not_to_have_title(title_or_reg_exp)expect(page).not_to_have_title(title_or_reg_exp, **kwargs)
Arguments
title_or_reg_exp str
| Pattern
Added in: v1.18#
Expected title or RegExp.
timeout float
(optional) Added in: v1.18#
Time to retry the assertion for in milliseconds. Defaults to 5000.
Returns
Added in: v1.20 pageAssertions.not_to_have_url
The opposite of expect(page).to_have_url() .
Usage
expect(page).not_to_have_url(url_or_reg_exp)expect(page).not_to_have_url(url_or_reg_exp, **kwargs)
Arguments
url_or_reg_exp str
| Pattern
Added in: v1.18#
Expected URL string or RegExp.
ignore_case bool
(optional) Added in: v1.44#
Whether to perform case-insensitive match. ignore_case option takes precedence over the corresponding regular expression flag if specified.
timeout float
(optional) Added in: v1.18#
Time to retry the assertion for in milliseconds. Defaults to 5000.
Returns
Added in: v1.20 pageAssertions.to_have_title
Ensures the page has the given title.
Usage
Sync
Async
import refrom playwright.sync_api import expect# ...expect(page).to_have_title(re.compile(r".*checkout"))
import refrom playwright.async_api import expect# ...await expect(page).to_have_title(re.compile(r".*checkout"))
Arguments
title_or_reg_exp str
| Pattern
Added in: v1.18#
Expected title or RegExp.
timeout float
(optional) Added in: v1.18#
Time to retry the assertion for in milliseconds. Defaults to 5000.
Returns
Added in: v1.20 pageAssertions.to_have_url
Ensures the page is navigated to the given URL.
Usage
Sync
Async
import refrom playwright.sync_api import expect# ...expect(page).to_have_url(re.compile(".*checkout"))
import refrom playwright.async_api import expect# ...await expect(page).to_have_url(re.compile(".*checkout"))
Arguments
url_or_reg_exp str
| Pattern
Added in: v1.18#
Expected URL string or RegExp.
ignore_case bool
(optional) Added in: v1.44#
Whether to perform case-insensitive match. ignore_case option takes precedence over the corresponding regular expression parameter if specified. A provided predicate ignores this flag.
timeout float
(optional) Added in: v1.18#
Time to retry the assertion for in milliseconds. Defaults to 5000.
Returns