Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

473
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda