I am trying to add else if /switch case in my test , but else if - it goes to only if case, if 'if' fail it doesn't go in else if it's happen in switch case also
it('Deve cadastrar um CNPJ válido', () => {
cy.get(':nth-child(2) > .kt-header__topbar-wrapper').click()
cy.get('.kt-header__topbar-item.show > .dropdown-menu > .kt-notification > .kt-notification__custom').should('be.visible')
cy.visit('/Company/Create')
cy.contains('Registration of the Establishment').should('be.visible')
cy.get(':nth-child(2) > .kt-option > .kt-option__control > .kt-radio > span').click()
cy.contains('Enter the CNPJ of the establishment you want to add below').should('be.visible')
cy.get('#searchCnpj')
.type(faker.br.cnpj())
.should('be.visible')
cy.get(':nth-child(2) > .form-group > .input-group > .input-group-append > .btn')
.click()
cy.contains('Establishment already registered.').then(($message) => {
if ($message.length > 0) {
cy.log('Establishment already registered.')
cy.get('#searchCnpj')
.clear()
.type(faker.br.cnpj())
cy.get(':nth-child(2) > .form-group > .input-group > .input-group-append > .btn').click()
} else {
cy.contains('Do you want to register it?').then(($confirmMessage) => {
if ($confirmMessage.length > 0) {
cy.log('Do you want to register it?')
cy.contains('Sim').click()
}
})
}
})
})
The error that appears in cypress: Timed out retrying after 4000ms: Expected to find content: 'Estabelecimento já cadastrado.' but never did.
What I want is: Enter CNPJ and click Consult
If the system displays "Establishment already registered", then the cypress must change the cnpj and click on Consult again until the message "Do you want to register" appears and click on "Yes"
If the system displays "Do you want to register it" then you must click "Yes"