cy.get('body').then(($body) => {
if ($body.find(selector).length > 0) {
//element exists do something
}
})
cy.get("selector_for_your_button").then($button => {
if ($button.is(':visible')){
//you get here only if button is visible
}
})
cy.get('section').should('have.class', 'container')