使用 Cypress 通过 Web 网关登录超时

Login through a web gateway with Cypress is timing out

我正在尝试对我的网络应用程序执行一些测试,但为此我必须登录外部网站,为此我的 beforeEach 语句是:

beforeEach(()=>{
    cy.visit('http://localhost:3001/')
    cy.get('#username')
        .type('user');
    cy.get('#password')
        .type('pass');
    cy.get('#fm1 > div > section.row.btn-row > input.btn.btn-submit.btn-block')
        .click();
})

预期的行为是,当我转到 localhost:3001 时,它会将我重定向到我设置登录凭据的另一个网站,并在单击登录后将我重定向到原始站点。

问题是我在外部网站上收到了这个

CypressError: Timed out after waiting '60000ms' for your remote page to load.

Your page did not fire its 'load' event within '60000ms'.

You can try increasing the 'pageLoadTimeout' value in 'cypress.json' to wait longer.

Browsers will not fire the 'load' event until all stylesheets and scripts are done downloading.

When this 'load' event occurs, Cypress will continue running commands.

Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: 'Test Drag and Drop, in cypr...'

我尝试增加 pageLoadTimeout,但它不起作用。

如果您的页面上有无法在 cypress 浏览器内解析的外部资源,就会发生这种情况。也许在您的环境中就是这种情况? 在我们的企业应用程序中更新 header-component 后,我遇到了类似的问题。突然间,所有端到端测试都因这个 "load event not fired" 错误而失败。

经过广泛的研究后,我偶然发现新插入的公司徽标是通过绝对外部 URL 包含的。通过在我们的 CI 中执行 cypress,此 URL 由于防火墙规则而被阻止。 这会导致页面加载事件受阻,从而导致测试失败。将图像 URL 更改为相对路径后一切正常。

所以,也许您的 "outer" 网站上有类似的案例?!