[英]Cypress: How to handle closing of window confirm triggered from an iframe
I need help on how to close a confirmation window which was triggered from an iframe.我需要有关如何关闭由 iframe 触发的确认 window 的帮助。 I am trying the code below, but this still can't close the confirm window.
我正在尝试下面的代码,但这仍然无法关闭确认 window。
cy.get('iframe[id="ParentMainContent_Frame"]').then(($iframe) => {
const $body = $iframe.contents().find('body')
const $win = $iframe[0].contentWindow
cy.stub($win,'confirm').as('windowConfirm')
cy.wrap($body)
.find('#ParentMainContent_MainContentMaster_ctl00_PlaceOrderButton').click().should(function () {
expect(this.windowConfirm).to.be.calledWith('Thank you for your Order!')
})
})
The button triggering this window is shown above:触发此 window 的按钮如上所示:
Hoping someone could take a look and help.希望有人可以看看和帮助。
Using cypress-iframe gives you more checks that the iframe loading has finished before you start testing it's contents.使用cypress-iframe可以让您在开始测试其内容之前更多地检查 iframe 加载是否已完成。
The downside is this library's methods yield body
but not the iframe window, though I think you can use body.ownerDocument.window
to get it.缺点是这个库的方法产生
body
,但不是 iframe window,尽管我认为您可以使用body.ownerDocument.window
来获取它。
cy.enter('iframe[id="ParentMainContent_Frame"]').then(getBody => {
const body = getBody();
const win = body.ownerDocument.window;
cy.spy(win,'confirm').as('windowConfirm'); // spy not stub
body.find('#ParentMainContent_MainContentMaster_ctl00_PlaceOrderButton')
.click()
.should(function () {
expect(this.windowConfirm).to.be.calledWith('Thank you for your Order!')
})
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.