Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid timeout error for cy.request()?

Tags:

cypress

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;})
like image 314
Avaiyarasi Narayanasamy Avatar asked Jul 03 '26 18:07

Avaiyarasi Narayanasamy


1 Answers

You can use responsetimeout in cypress.json file. Cypress Docs

like image 96
das Avatar answered Jul 05 '26 11:07

das



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!