Slow form submission and configuring request timeout

52 views Asked by At

I'm using Cypress for End-to-End testing.

Problem 1: Slow Form Submission

When I submit a form, the associated POST request returns a 200 status code. However, there's a significant delay when using Cypress. Normally, form submission takes 7-8 seconds, but with Cypress, it takes more than 20 seconds. What might be causing this delay, and how can I optimize it?

Problem 2: Cypress timeout for request and response

I've noticed that Cypress has built-in timeouts for requests and responses. In my tests, I need to wait for a specific request to complete and for a certain response status code before proceeding.

Cypress allows for defining a maximum wait time for requests (e.g., 25 seconds as configured in my Cypress configuration file), but I need Cypress to wait until the request is responded to with a status code.

How can I configure Cypress to wait until the request receives a specific status code before proceeding?

enter image description here

1

There are 1 answers

1
Aladin Spaz On

If you look at the cy.wait() command, there is a responseTimeout option which overrides the global responseTimeout for this particular request.

So, what should work is

cy.wait('@postVehicle', {responseTimeout: 30_000}).then(...

As for optimization, that's a lot harder to diagnose remotely from just the test code, however if it's server-related you can get an immediate response by mocking the response in the intercept.

cy.intercept('POST', 'backend/vehicle', {<mock response here>})
  .as('postVehicle)