javascript – 使用赛普拉斯通过网关登录即可

我正在尝试为我的webapp执行一些测试,但要做到这一点,我必须登录到外部网站,为了做到这一点,我的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后,我遇到了类似的问题.突然间,所有的e2e测试都因为“加载事件未被触发”错误而失败.

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

那么,也许你的“外部”网站也有类似的案例?!

点赞