In Cypress I'm simply trying to to close a filter using it's class "const filterRemoveElement = '.position-absolute > img';" But the problem is that if cypress found that element then it's passing the test case, if there are no filters applied then it's failing the test case, not going for else condition
cy.get(filterElement).then(($elements) => {
if ($elements.length > 0) {
cy.get('.d-inline-block').find('.dropdown-toggle').then(($filter) =>{
if($filter.length > 1){
cy.get(filterRemoveElement).then(($remove) => {
if($remove.length > 0) {
cy.get(filterRemoveElement).click({ multiple: true });
} else {
cy.log('No filter remove button present, skipping "remove filter" step.');
}
})
} else {
cy.log('No filter dropdown present, skipping "remove filter" step.');
}
})
} else {
cy.log('No filter section present, skipping "remove filter" step.');
}
})
try below