【问题标题】:cy.spy() or cy.stub() is not working for new tab opened with different domain namecy.spy() 或 cy.stub() 不适用于使用不同域名打开的新选项卡
【发布时间】:2022-11-19 03:40:58
【问题描述】:

单击我的应用程序中的图像后,将打开一个具有不同域 URL 的新选项卡,但出现以下错误

代码 -

cy.window().then((win) => {
   cy.spy(win, 'open').as('@redirect')
});

cy.get('webElement').click();
cy.get('@redirect').should('be.called')

Note: 
1. webElement clicked is 'img' not anchor and it does not have any 'href' and 'target' attribute.
2. Same code is working fine when new tab url is of same domain.

DOM Error

【问题讨论】:

    标签: cypress cypress-custom-commands


    【解决方案1】:

    别名不应命名为@redirect 而是重定向:

    cy.spy(win, 'open').as('@redirect')
    

    正确的:

    cy.spy(win, 'open').as('redirect')
    

    您正确地断言了它。

    https://docs.cypress.io/api/commands/as#DOM-element

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2015-07-23
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      相关资源
      最近更新 更多