playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: Add `toBeValid`, `toBeInvalid` assertions

Open jacobrask opened this issue 7 months ago • 0 comments

🚀 Feature Request

The browser accessibility tree will expose an "Invalid user entry" property which is true either if an input is invalid from native constraints validation or from aria-invalid, similar to checked vs aria-checked. toBeValid and toBeInvalid assertions and isValid and isInvalid locator methods would be very useful to be able to write tests that work with either.

Example

All of these should trigger toBeInvalid():

<input type="text" aria-invalid>
<input type="text" required>
input.setCustomValidity('error');

Motivation

It would make writing tests for form validation easier and less focused on implementation details such as specific attributes or styles.

Related to #34839

jacobrask avatar Jun 09 '25 08:06 jacobrask