crooked-microphone-65524
02/01/2023, 2:40 AMwonderful-match-15836
02/06/2023, 3:43 PMcy.findByLabelText('First name', {
selector: '[data-test="header-form-field"]',
}).click()
In many cases I can simplify by using cy.contains()
. For example:
cy.contains('button', 'Log In')
or cy.contains('a', 'Home')
And I prefer these to asserting the role, since these elements have roles by default and I want developers using the real elements, not putting role='button'
on a div.
I don't believe it's possible to get the true computed role of an element, as it appears in the accessibility tree, from JS at the moment, but Testing Library style locators are better in my book anyway.