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

474
Visualizações
Cypress how to close window print dialog

I am looking to perform action on print window using cypress.

Manually when I click on the print button I get the print window like Image 1. But when I run the same script in cypress test runner, I get the print windows as in Image 2.

I am aware that action on such window can be done using a stub. But I cant even inspect print window I get in test runner i.e. Image 2. so what shall be the locator of cancel button ??

let printStub
          cy.window().then(win => {
                printStub = cy.stub(win, 'print')
                cy.get(HOW DO I GET THE LOCATOR).click().then(()=>{
                    expect(win.print).to.be.called
                })
            })

Image 1: enter image description here

Image 2: enter image description here

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

0

I'm not sure what causes the difference in the two print windows, but tecnically you don't need to test the actually printing part, just that window.print has been called.

If you agree, then follow this example Replace a method with a function, adding a dummy function as 3rd parameter to the stub.

let printCalled = false
cy.stub(cy.state('window'), 'print', () => {
  printCalled = true
})

cy.get('the-print-button-selector').click()  // app calls window.print
  .should(() => expect(printCalled).to.eq(true))

or just assert the call happened

const stub = cy.stub(cy.state('window'), 'print', () => {})  // replace print with do-nothing fn

cy.get('the-print-button-selector').click()  // app calls window.print
  .should(() => expect(stub).to.be.called)
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