LocatorAssertions
Playwright\Assertions\LocatorAssertionsInterface
Methods
toBeAttached()
selfAsserts 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()
selfAsserts the element can be edited: enabled, not readonly, and accepting input.
function toBeEditable(?AssertionOptions $options = null): self
toBeInViewport()
selfAsserts 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()
selffunction toBeVisible(?AssertionOptions $options = null): self
toBeHidden()
selffunction toBeHidden(?AssertionOptions $options = null): self
toBeChecked()
selffunction toBeChecked(?AssertionOptions $options = null): self
toBeEnabled()
selffunction toBeEnabled(?AssertionOptions $options = null): self
toBeDisabled()
selffunction toBeDisabled(?AssertionOptions $options = null): self
toBeEmpty()
selffunction toBeEmpty(?AssertionOptions $options = null): self
toBeFocused()
selffunction toBeFocused(?AssertionOptions $options = null): self
toHaveFocus()
selffunction toHaveFocus(?AssertionOptions $options = null): self
toHaveText()
selffunction toHaveText(string|array $expected, ?AssertionOptions $options = null): self
toContainText()
selffunction toContainText(string $expected, ?AssertionOptions $options = null): self
toHaveExactText()
selffunction toHaveExactText(string $expected, ?AssertionOptions $options = null): self
toHaveValue()
selffunction toHaveValue(string $expected, ?AssertionOptions $options = null): self
toHaveAttribute()
selffunction toHaveAttribute(string $name, string $expected, ?AssertionOptions $options = null): self
toHaveCSS()
selffunction toHaveCSS(string $name, string $expected, ?AssertionOptions $options = null): self
toHaveId()
selffunction toHaveId(string $expected, ?AssertionOptions $options = null): self
toHaveClass()
selffunction toHaveClass(string|array $expected, ?AssertionOptions $options = null): self
toHaveCount()
selffunction toHaveCount(int $expected, ?AssertionOptions $options = null): self
toHaveJSProperty()
selfAsserts 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()
selffunction toHaveValues(array|string $expected, ?AssertionOptions $options = null): self
toHaveRole()
selfAsserts 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()
selfAsserts 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()
selfAsserts 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()
selfAsserts 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()
selfAsserts 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()
selfAsserts 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()
selffunction not(): self
withTimeout()
selffunction withTimeout(int $timeoutMs): self
withPollInterval()
selffunction withPollInterval(int $pollIntervalMs): self