I need to check multiple pages for whether a list exists, and if so, get the length of the list. This works fine except some pages do not have lists (this is intentional). Is there any way I can use .should('exist') to check if the list is there and if so check it, otherwise just continue?
I currently have this test:
if (cy.get('.mt-5').should('exist')) {
cy.get('.mt-5')
.find('li')
.then(($listItems) => {
const listLength = $listItems.length;
cy.wrap(listLength).as('listLength');
});
}
however, this just causes a timeout when it gets to the if
statement as it is looking for .mt-5
which does not always exist.