We search for an invalid element as following:
const invalidClasses = '.invalid, .invalid-default';
getInvalidElement() {
cy.get(invalidClasses)
};
Now I have another function which accepts the element and checks if it has the invalid classes:
isInvalid(selector) {
return cy.get(selector).should('have.class','invalid');
}
How can I check that the element has any of the two classes?
I know I can do
cy.get(selector).invoke('attr','class').should('match','/invalid/');
But what if the classes were different?
(Also the conditional testing does not apply to this case, there is no logic whether it's the first of the classes or the second one, we just want more abstract class for reusing)
Tip: if a Cypress test fails with "element is not visible" error, but you are sure the element should be visible, you can debug the visibility check yourself by stepping through the Cypress. dom. isVisible code, see Debug the Element Visibility Problems in Cypress.
I guess it will works for you:
cy.get('section')
.should('have.class', 'container')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With