【问题标题】:How to avoid timeout error for cy.request()?如何避免 cy.request() 的超时错误?
【发布时间】:2021-02-05 10:21:42
【问题描述】:

我正在使用 cy.request() 方法发送 API 请求并在我的 cypress 测试中读取响应。但有时测试会失败并出现以下错误:

CypressError: cy.request() timed out waiting 30000ms for a response from your server.

我通过在请求正文中传入 timeout: 50000 选项来增加超时值,但有时它仍然会失败,尤其是在响应很大时。有没有其他方法可以避免请求超时错误?

下面是我的代码:

cy.request({
    method: "POST",
    url:"http://localhost:3001/codes/search?searchText=" +searchText.replace(" ", "%20") +"&page[size]=100",
    body: {
      data: {
        type: "ern:code-search-request",
        attributes: {
          CodeCategory: filterOption
        }
      }
    },
    timeout: 50000
  }).then((response: any) => {return response;})

【问题讨论】:

  • 嘿,只是好奇,您是否尝试过在 Postman 或类似工具中点击端点并检查这种情况下的响应时间?

标签: cypress


【解决方案1】:

您可以在 cypress.json 文件中使用responsetimeoutCypress docs

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2017-07-22
  • 1970-01-01
  • 2016-07-11
  • 1970-01-01
  • 2020-07-31
  • 1970-01-01
  • 2012-01-11
  • 2018-06-18
  • 2011-02-16
相关资源
最近更新 更多