LocatorAssertions

Playwright\Assertions\LocatorAssertionsInterface

Methods

toBeAttached()

self

Asserts the element is present in the DOM, visible or not. Weaker than toBeVisible(): a display:none element is attached.

function toBeAttached(?AssertionOptions $options = null): self

toBeEditable()

self

Asserts the element can be edited: enabled, not readonly, and accepting input.

function toBeEditable(?AssertionOptions $options = null): self

toBeInViewport()

self

Asserts the element intersects the viewport. AssertionOptions::$ratio sets the fraction of the element's own area that must be visible, between 0 and 1. Out of that range throws.

function toBeInViewport(?AssertionOptions $options = null): self

toBeVisible()

self
function toBeVisible(?AssertionOptions $options = null): self

toBeHidden()

self
function toBeHidden(?AssertionOptions $options = null): self

toBeChecked()

self
function toBeChecked(?AssertionOptions $options = null): self

toBeEnabled()

self
function toBeEnabled(?AssertionOptions $options = null): self

toBeDisabled()

self
function toBeDisabled(?AssertionOptions $options = null): self

toBeEmpty()

self
function toBeEmpty(?AssertionOptions $options = null): self

toBeFocused()

self
function toBeFocused(?AssertionOptions $options = null): self

toHaveFocus()

self
function toHaveFocus(?AssertionOptions $options = null): self

toHaveText()

self
function toHaveText(string|array $expected, ?AssertionOptions $options = null): self

toContainText()

self
function toContainText(string $expected, ?AssertionOptions $options = null): self

toHaveExactText()

self
function toHaveExactText(string $expected, ?AssertionOptions $options = null): self

toHaveValue()

self
function toHaveValue(string $expected, ?AssertionOptions $options = null): self

toHaveAttribute()

self
function toHaveAttribute(string $name, string $expected, ?AssertionOptions $options = null): self

toHaveCSS()

self
function toHaveCSS(string $name, string $expected, ?AssertionOptions $options = null): self

toHaveId()

self
function toHaveId(string $expected, ?AssertionOptions $options = null): self

toHaveClass()

self
function toHaveClass(string|array $expected, ?AssertionOptions $options = null): self

toHaveCount()

self
function toHaveCount(int $expected, ?AssertionOptions $options = null): self

toHaveJSProperty()

self

Asserts a JavaScript property of the element equals the expected value. Reads the live DOM property, not the HTML attribute: an input the user typed into has value "typed" here and "" as an attribute. Arrays and objects are compared structurally, key by key.

function toHaveJSProperty(string $name, mixed $expected, ?AssertionOptions $options = null): self

toHaveValues()

self
function toHaveValues(array|string $expected, ?AssertionOptions $options = null): self

toHaveRole()

self

Asserts the element's ARIA role. Uses the explicit role attribute when present, otherwise the role implied by the tag name. This is not the full computed accessibility role: roles derived from attributes, such as an input's type, are not resolved.

function toHaveRole(string $role, ?AssertionOptions $options = null): self

toContainClass()

self

Asserts the element carries the given classes, among others. Space-separated tokens are all required, in any order; extra classes on the element are ignored. An expectation with no token throws.

function toContainClass(string $expected, ?AssertionOptions $options = null): self

toHaveAccessibleName()

self

Asserts the element's accessible name. Resolves the first non-empty of aria-label, aria-labelledby, the associated label element and the element's own text, which is short of the full accessible name computation. Whitespace is collapsed on both sides and AssertionOptions::$ignoreCase relaxes the comparison.

function toHaveAccessibleName(string $expected, ?AssertionOptions $options = null): self

toHaveAccessibleDescription()

self

Asserts the element's accessible description. Resolves the first non-empty of aria-description, aria-describedby and the title attribute, which is short of the full accessible description computation. Whitespace is collapsed on both sides and AssertionOptions::$ignoreCase relaxes the comparison.

function toHaveAccessibleDescription(string $expected, ?AssertionOptions $options = null): self

toHaveAccessibleErrorMessage()

self

Asserts the error message the element exposes through aria-errormessage. Resolves to an empty string unless the element is flagged invalid by aria-invalid or fails constraint validation. Whitespace is collapsed on both sides and AssertionOptions::$ignoreCase relaxes the comparison.

function toHaveAccessibleErrorMessage(string $expected, ?AssertionOptions $options = null): self

toMatchAriaSnapshot()

self

Asserts the element's ARIA snapshot equals the expectation. Compares the YAML of LocatorInterface::ariaSnapshot() as text, ignoring blank lines, trailing whitespace and the indentation shared by every line. The expectation describes the whole subtree, not a subset of it.

function toMatchAriaSnapshot(string $expected, ?AssertionOptions $options = null): self

not()

self
function not(): self

withTimeout()

self
function withTimeout(int $timeoutMs): self

withPollInterval()

self
function withPollInterval(int $pollIntervalMs): self