繁体   English   中英

赛普拉斯:如何处理从 iframe 触发的 window 确认关闭

[英]Cypress: How to handle closing of window confirm triggered from an iframe

我需要有关如何关闭由 iframe 触发的确认 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!')
        })
    }) 

DOM

触发此 window 的按钮如上所示:

希望有人可以看看和帮助。

使用cypress-iframe可以让您在开始测试其内容之前更多地检查 iframe 加载是否已完成。

缺点是这个库的方法产生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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM