I have a cypress test that on clicking a button the system redirects to a new window. I've tried some solutions (invoke,stub) without success.
I need to do some testing but I need it to always be redirected on the same screen as cypress doesn't support multiple windows.
My button code:
<button id="cmdEnviar" name="cmdEnviar" type="button" onclick="TrPage._autoSubmit('_id5','cmdEnviar',event,1);return false;" class="x7j">Enviar</button>
My code:
it('register new user', function() {
cy.visit('/')
cy.get('#txtLogin').type(Cypress.env('login'))
cy.get('#txtSenha').type(Cypress.env('pass'))
cy.get('#btnEnviar').click()
cy.get('#cmbSistemas').select(11)
cy.get('#cmdEnviar').click() //here is the button
//here is redirected to another window
cy.contains('Colaborador').click()
cy.contains('Cadastro').click()
})
Could anyone help me, if there is any solution?
Unfortunately, without seeing what your onclick event actually does, I can't recommend a strategy for validating the behavior of onclick is functioning as intended.
Instead, we can validate that the button has the correct onclick attribute value.
...
cy.get('#cmdEnviar')
.should('have.attr', 'onclick', "TrPage._autoSubmit('_id5','cmdEnviar',event,1);return false;");
...