playwright
playwright copied to clipboard
[Feature]: Add `toBeValid`, `toBeInvalid` assertions
🚀 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