84
rated 0 times
[
87]
[
3]
/ answers: 1 / hits: 42039
/ 4 Years ago, mon, may 25, 2020, 12:00:00
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)
More From » cypress