javascript - 如何将 Cypress 配置为更长时间(或无限期)等待 BaseUrl?

标签 javascript automated-tests cypress end-to-end

我在 docker-compose.yml 中使用这个 Cypress 图像来运行端到端测试:cypress/included:6.1.0

当测试运行器启动时,它将验证是否可以通过 baseUrl 访问服务器。如果没有,它会重试 3 次。

我的服务和 Web 服务器需要更多时间才能启动。

如何增加此检查的超时和/或重试次数。

最好,在我的例子中,我想要一个重试直到成功的策略,即无限期重试/等待。

我检查了 Timeouts部分和更一般的 cypress.json 文档。然而,这些超时或重试似乎都与此行为无关。

有这个设置吗?


澄清:这不是我实现(或想要)作为我的规范的一部分的检查。据我所知,这是图像中默认命令 cyprus run 的一个特性。如果可能的话,我想在不添加或修改测试本身的情况下进行配置。

这是 cypress 在容器中启动时的 docker-compose 控制台输出:

cypress_1         | Cypress could not verify that this server is running:
cypress_1         |
cypress_1         |   > http://localhost:5000
cypress_1         |
cypress_1         | We are verifying this server because it has been configured as your `baseUrl`.
cypress_1         |
cypress_1         | Cypress automatically waits until your server is accessible before running tests.
cypress_1         |
cypress_1         | We will try connecting to it 3 more times...
cypress_1         | We will try connecting to it 2 more times...
cypress_1         | We will try connecting to it 1 more time...
cypress_1         |
cypress_1         | Cypress failed to verify that your server is running.
cypress_1         |
cypress_1         | Please start this server and then run Cypress again.
cypress_1 exited with code 1

最佳答案

在使用类似 wait-on 的实用程序调用 cypress run 之前,您应该确保您的服务器正在运行或 start-server-and-test .

Cypress 对 baseUrl 的检查是最后的礼貌检查,这样您就不会在未运行的服务器上运行整个测试套件。

有关在运行 Cypress 之前确保服务器正在运行的提示,请在此处查看 Cypress 文档:https://on.cypress.io/continuous-integration#Boot-your-server

关于javascript - 如何将 Cypress 配置为更长时间(或无限期)等待 BaseUrl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65358642/

相关文章:

Javascript 替换正则表达式不支持大写

Cypress -等待由UI操作触发的xhr请求

url - Cypress :如何检查按钮网址?

javascript - jQuery:如何在不同的字符串中添加一个<br/>换行符来分隔2中的句子?

javascript - 我想为这个径向渐变和 div 生成边框

javascript - 使用 Webpack 时无法将 CSS 链接到 JSX

automated-tests - UI 自动化白色框架 "NonComVisibleBaseClass was detected"异常

testing - 如何将 TestRail 与 Jenkins 集成?

javascript - 测试 d3(和其他基于 SVG 的)Web 应用程序

cypress - 如何使用 Cypress 清除多选输入?