File: test-assertions.md | Updated: 11/18/2025
On this page
List of assertions
| Assertion | Description | | --- | --- | | expect(locator).to_be_attached() | Element is attached | | expect(locator).to_be_checked() | Checkbox is checked | | expect(locator).to_be_disabled() | Element is disabled | | expect(locator).to_be_editable() | Element is editable | | expect(locator).to_be_empty() | Container is empty | | expect(locator).to_be_enabled() | Element is enabled | | expect(locator).to_be_focused() | Element is focused | | expect(locator).to_be_hidden() | Element is not visible | | expect(locator).to_be_in_viewport() | Element intersects viewport | | expect(locator).to_be_visible() | Element is visible | | expect(locator).to_contain_class() | Element has specified CSS classes | | expect(locator).to_contain_text() | Element contains text | | expect(locator).to_have_accessible_description() | Element has a matching accessible description | | expect(locator).to_have_accessible_name() | Element has a matching accessible name | | expect(locator).to_have_attribute() | Element has a DOM attribute | | expect(locator).to_have_class() | Element has a class property | | expect(locator).to_have_count() | List has exact number of children | | expect(locator).to_have_css() | Element has CSS property | | expect(locator).to_have_id() | Element has an ID | | expect(locator).to_have_js_property() | Element has a JavaScript property | | expect(locator).to_have_role() | Element has a specific ARIA role | | expect(locator).to_have_text() | Element matches text | | expect(locator).to_have_value() | Input has a value | | expect(locator).to_have_values() | Select has options selected | | expect(locator).to_match_aria_snapshot() | Element matches provided Aria snapshot | | expect(page).to_have_title() | Page has a title | | expect(page).to_have_url() | Page has a URL | | expect(response).to_be_ok() | Response has an OK status |
Custom Expect Message
You can specify a custom expect message as a second argument to the expect function, for example:
expect(page.get_by_text("Name"), "should be logged in").to_be_visible()
When expect fails, the error would look like this:
def test_foobar(page: Page) -> None:> expect(page.get_by_text("Name"), "should be logged in").to_be_visible()E AssertionError: should be logged inE Actual value: NoneE Call log:E LocatorAssertions.to_be_visible with timeout 5000msE waiting for get_by_text("Name")E waiting for get_by_text("Name")tests/test_foobar.py:22: AssertionError
Setting a custom timeout
You can specify a custom timeout for assertions either globally or per assertion. The default timeout is 5 seconds.
conftest.py
from playwright.sync_api import expectexpect.set_options(timeout=10_000)
test_foobar.py
from playwright.sync_api import expectdef test_foobar(page: Page) -> None: expect(page.get_by_text("Name")).to_be_visible(timeout=10_000)