example https://rahulshettyacademy.com/AutomationPractice/ on click window
I have tried with get the property of onclick but its displaying undefined, if any one have a code please post here.
example https://rahulshettyacademy.com/AutomationPractice/ on click window
I have tried with get the property of onclick but its displaying undefined, if any one have a code please post here.
The "Open Window" button uses the window.open
method to load a new url in a new browser window. There are two ways to test this.
Stubbing
You can stub the window.open
method and check it was called.
cy.visit(url, {
onBeforeLoad (win) {
cy.stub(win, 'open').as('open')
}
})
cy.get('#openwindow').click()
cy.get('@open').should('have.been.calledOnce')
Loading on the same window
You can also have the url loaded in the same window as the cypress test runner.
cy.visit(url)
cy.window().then(win => {
cy.stub(win, 'open').callsFake((url, target) => {
expect(target).to.be.undefined
// call the original `win.open` method
// but pass the `_self` argument
return win.open.wrappedMethod.call(win, url, '_self')
}).as('open')
})
cy.get('#openwindow').click()
cy.get('@open').should('have.been.calledOnce')
Gleb has good reading material on this.