【问题标题】:cypress unable to assert new window url赛普拉斯无法断言新窗口 URL
【发布时间】:2020-06-28 04:50:00
【问题描述】:

我在网站https://www.qatestpage.com/page1 点击'testlink'后

新窗口https://google.com 已打开。

我想断言新窗口的 url 是正确的。

这是我的代码:

  cy.get('a[href*="testlink"]').eq(0).click()
   cy.location().should((loc) => {
    expect(loc.href).to.include('https://google.com')
  })

错误:

Timed out retrying: expected 'https://www.qatestpage.com/page1' to include 'https://google.com'

【问题讨论】:

    标签: cypress


    【解决方案1】:

    赛普拉斯不支持多标签功能。因此,当您说cy.location() 时,它总是会返回您单击testlink 的窗口。所以这就是它给你这个https://www.qatestpage.com/page1而不是https://google.com的原因

    请参考这里https://docs.cypress.io/guides/references/trade-offs.html#Multiple-tabs

    【讨论】:

      【解决方案2】:

      试试:

      cy.url().then(str1 => {
          expect(str1).to.include(str2)
      })
      

      其中 str1 将捕获窗口的当前 url,而 str2 是您要检查它是否存在于 str1 中的字符串。

      【讨论】:

        猜你喜欢
        • 2022-07-18
        • 2021-12-22
        • 2021-12-21
        • 1970-01-01
        • 2021-01-02
        • 1970-01-01
        • 1970-01-01
        • 2020-09-12
        • 1970-01-01
        相关资源
        最近更新 更多