Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
Cypress - triggering POST request opens URL of response

I have a test where I want to create a new document. In order to create the document I need to click on a "Save" button. Clicking "Save" triggers a POST request and opens the newly created document in a portlet on the same page.

However, when I do this in Cypress, clicking the save button opens the URL of the POST request in the browser. This page simply displays the response of the POST request.

{"response":"248"}

How is it possible that clicking the button manually opens the newly created document, while clicking the button in cypress opens a new URL?

This is the cypress code:

cy.visit(url_document_sets)
cy.get('.is_flatten').click({force:true}
cy.get('#TcDocumentFile_valid_from').type(current_date)
cy.get('.k-button').contains('Speichern') //Speichern = Save

Which is exactly what I do manually. I go the the URL, click 2 buttons, then click the Save button. Doing this in Cypress though will open the URL of the POST request https://**********/index.php?r=tc/documentSet/documentSet/saveFile&language=de in the browser.

Cypress does not throw an error, it just opens the URL.

I know this question is very hard to reproduce, so if there is anything I can provide to make the question clearer, please help me out.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I don't know why Cypress doesn't just handle it, could make a guess but it would not help.

To handle it yourself, you could try to stub the call and manually set the document to what is returned.

I'm assuming when you say "opens the newly created document" it replaces the whole browser document and not just a part of the page.

const routeMatcher = {
  method: 'POST',
  url: '**/index.php?r=tc/documentSet/documentSet/saveFile&language=de',
  hostname: 'localhost'
}

cy.intercept(routeMatcher, (req) => {
  req.continue((res) => {
    console.log(res.body)      // double-check in console you have "document"
                               // you may have to get it from a property of body
    cy.state('document', res.body)
  })
}).as('newDoc')

cy.visit(url_document_sets)
cy.get('.is_flatten').click({force:true}
cy.get('#TcDocumentFile_valid_from').type(current_date)
cy.get('.k-button').contains('Speichern') //Speichern = Save

cy.wait('@newDoc')
// continue testing

If you have difficulty finding the new document property, please add res to the question and I'll take a look.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda