node.js - 避免使用 cy.wait() 等待页面由于中止的获取请求而加载 cypress

标签 node.js timeout cypress

我正在运行一个 cypress 测试,需要在单击元素并登录之前加载页面,但由于某种原因失败(并中止)的 GET 请求导致页面永远加载并最终超时除非我在 cy.click() 调用之前添加一个 cy.wait(6000) 。我需要以某种方式等待页面加载而不使用 cy.wait()。鉴于我无法修复中止的 GET 请求,我该怎么做?

enter image description here

  cy.visit(loginUrl)
  cy.url().should('contain', '#/loginPortal')
  cy.wait(6000) //Allows page to load before trying to log in, needs to be removed
  cy.contains('ButtonText').click()

最佳答案

在断言之前,您可以让 Cypress 等待任何特定的 XHR 调用。等待多长时间由 responseTimeout configuration 定义.

cy.server();
cy.route('**/api/getData').as('getData');
cy.visit('/home');
cy.wait('@getData');
cy.contains('ButtonText').click()

Cypress best practices: Unnecessary-Waiting.

Cypress docs on wait Alias.

关于node.js - 避免使用 cy.wait() 等待页面由于中止的获取请求而加载 cypress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50685393/

相关文章:

c# - Azure Blob 客户端设置较短的超时

Cypress,如何检查输入到字段中的文本?

vuejs3 - 如何获取Vite环境变量?

javascript - 如何提高JS函数式代码的性能

javascript - 如何在 MongoDB 中检索子文档引用

c# - 在 C# 中禁用单元测试的超时

wpf - Azure StorageClient 瞬时连接测试 - 挂起

typescript - Cypress cucumber 预处理器自定义参数类型与 typescript

node.js - AWS S3 x-amz-meta 错误与非字符串值 : InvalidHeader and InvalidParameterType

node.js - http - 更改请求网址?