如何修改Cypress 测试代码中默认的超时时间(timeout)

661 阅读1分钟

我使用 Cypress 对 SAP 官网进行自动化操作时,遇到了如下的错误消息:

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

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

SAP 官网的首页,在试图被 cy.visit 指令加载后,在默认的 1 分钟 超时时间内,没有加载成功。

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.

在 SAP 官网没有结束加载所有的 stylesheets 即 CSS 文件和脚本文件之前,浏览器不会 fire load 事件。

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

如果没有 load 事件发生,Cypress 就不会继续执行 cy.visit 之后的指令。

解决方案

修改 cy.visit 指令默认的超时时间即可:

cy.visit('https://www.sap.com', { timeout: 300000 });