3
votes

I am using cy.request() method to send API requests and read the response in my cypress tests. But sometimes the tests fail with the following error:

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

I have increased the timeout value by passing in timeout: 50000 option in the request body, but still, it is failing sometimes especially when the response is huge. Is there any other way to avoid the request timeout error?

Below is my code:

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;})
1
Hey Just curious, Have you tried to hit the endpoint in Postman or a similar tool and check the response time in that case?Alapan Das

1 Answers

0
votes

There is no officially provided way (simply in the API). 50 seconds is a long time, but if you think you need more, add a 00. 5000 seconds is over an hour. If that isn't enough, add three - that's over half a day. One more zero and you'r at almost at 6 days - these aren't reasonable response times in this day and age, and likely there's an error if you still hit timeout.

So in short, why not add two or three zeros. That should be as good as infinity.