LocatorAssertions
The LocatorAssertions class provides assertion methods that can be used to make assertions about the Locator state in the tests.
- Sync
- Async
from playwright.sync_api import Page, expect
def test_status_becomes_submitted(page: Page) -> None:
# ..
page.get_by_role("button").click()
expect(page.locator(".status")).to_have_text("Submitted")
from playwright.async_api import Page, expect
async def test_status_becomes_submitted(page: Page) -> None:
# ..
await page.get_by_role("button").click()
await expect(page.locator(".status")).to_have_text("Submitted")
Methods
not_to_be_attached
Added in: v1.33The opposite of expect(locator).to_be_attached().
Usage
expect(locator).not_to_be_attached()
expect(locator).not_to_be_attached(**kwargs)
Arguments
-
Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_checked
Added in: v1.20The opposite of expect(locator).to_be_checked().
Usage
expect(locator).not_to_be_checked()
expect(locator).not_to_be_checked(**kwargs)
Arguments
-
timeout
float (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_disabled
Added in: v1.20The opposite of expect(locator).to_be_disabled().
Usage
expect(locator).not_to_be_disabled()
expect(locator).not_to_be_disabled(**kwargs)
Arguments
-
timeout
float (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_editable
Added in: v1.20The opposite of expect(locator).to_be_editable().
Usage
expect(locator).not_to_be_editable()
expect(locator).not_to_be_editable(**kwargs)
Arguments
-
timeout
float (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_empty
Added in: v1.20The opposite of expect(locator).to_be_empty().
Usage
expect(locator).not_to_be_empty()
expect(locator).not_to_be_empty(**kwargs)
Arguments
-
timeout
float (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_enabled
Added in: v1.20The opposite of expect(locator).to_be_enabled().
Usage
expect(locator).not_to_be_enabled()
expect(locator).not_to_be_enabled(**kwargs)
Arguments
-
timeout
float (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_focused
Added in: v1.20The opposite of expect(locator).to_be_focused().
Usage
expect(locator).not_to_be_focused()
expect(locator).not_to_be_focused(**kwargs)
Arguments
-
timeout
float (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_hidden
Added in: v1.20The opposite of expect(locator).to_be_hidden().
Usage
expect(locator).not_to_be_hidden()
expect(locator).not_to_be_hidden(**kwargs)
Arguments
-
timeout
float (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_in_viewport
Added in: v1.31The opposite of expect(locator).to_be_in_viewport().
Usage
expect(locator).not_to_be_in_viewport()
expect(locator).not_to_be_in_viewport(**kwargs)
Arguments
-
Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns
not_to_be_visible
Added in: v1.20The opposite of expect(locator).to_be_visible().
Usage
expect(locator).not_to_be_visible()
expect(locator).not_to_be_visible(**kwargs)
Arguments
-
timeout
float (optional) Added in: v1.18#Time to retry the assertion for in milliseconds. Defaults to
5000
.
Returns