window.print
Stub You can find this recipe shown in the video Stub window.print Method.
window.print
method
App calls the <p>
Click on the button to print this page
<button id="print">🖨</button>
</p>
<script>
document
.getElementById('print')
.addEventListener('click', () => {
window.print()
})
</script>
cy.window().then((w) => {
cy.stub(w, 'print').as('print')
})
cy.get('#print').click()
cy.get('@print').should('be.calledOnce')
Onclick button attribute
<p>
Click on the button to print this page
<button id="print" onclick="print()">🖨</button>
</p>
cy.window().then((w) => {
cy.stub(w, 'print').as('print')
})
cy.get('#print').click()
cy.get('@print').should('be.calledOnce')