Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
Cypress - How to redirect without opening a new window

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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;");
...
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!