Angular Cypress.io 使用 Google 登录弹出窗口进行测试 window

Angular Cypress.io test with Google Login popup window

是否可以使用 Google 身份验证弹出窗口 window 使用 Cypress.io 登录到 Google 帐户?

我可以打开 window,但是 Cypress 无法检测到电子邮件输入字段的 ID。

错误是:"CypressError: Timed out retrying: Expected to find element: '#identifierId', but never found it."

it('Login', function() {
    cy.visit('home')
    cy.get('#signin-button').click()
    cy.get('#google-login-button').click()
    // cy.wait(1500) // wait doesn't help
    cy.get('#identifierId')
    .type('user@gmail.com') // <<-- error here
  })

检查 DOM 元素是否可见。 identifierId 不可见

由于 Cypress 尚未完全实现 iframe support,因此无法正常工作。

但是,赛普拉斯不建议在您的测试中访问第 3 方应用程序。这有很多原因,包括:

  • 这非常耗时并且会减慢您的测试速度。
  • 第 3 方网站可能已更改或更新其内容。
  • 第 3 方网站可能存在您无法控制的问题。
  • 第 3 方站点可能会检测到您正在通过脚本进行测试并阻止您。
  • 第 3 方网站可能是 运行 A/B 个广告系列。

赛普拉斯概述了访问您无法控制的第 3 方网站的缺点以及他们文档中的一些解决方法。 I suggest reading the full explanation here.