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

480
Views
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 answers
Answer question

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 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!