小编Ava*_*amy的帖子

如何避免 cy.request() 超时错误?

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

CypressError:等待服务器响应cy.request()超时。30000ms

我通过在请求正文中传递 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;})
Run Code Online (Sandbox Code Playgroud)

cypress

6
推荐指数
1
解决办法
8313
查看次数

标签 统计

cypress ×1