cypress-io/cypress-realworld-testing-course-app

Issue with cy.visit() [> Error: ESOCKETTIMEDOUT] Timeout Despite Local Access

Closed this issue · 1 comments

Even after running the web app, I continue to encounter the following error, despite being able to access localhost:3000 through the browser:

cy.visit() failed trying to load:

http://localhost:3000/

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

> Error: ESOCKETTIMEDOUT
Screenshot 2024-07-18 at 12 24 19 PM

Here’s how the web app appears when accessed locally:

Screenshot 2024-07-18 at 12 34 39 PM

I want to share a solution that worked for me when using Cypress with localhost, in case anyone faces the same issue:

Solution that worked for me

Solution 1: Use Your IP Address

Instead of accessing cy.visit("http://localhost:3000"), swap localhost with your own IP address. To get your IP on a Mac, run the following command:

ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\  -f2

Your Cypress test would look something like this:

cy.visit("http://192.168.86.37:3000")

Other Solutions I Tried but Did Not Work

Solution 2: Accept-Encoding Headers

I tried setting custom headers, but it didn't resolve the issue:

cy.visit("http://localhost:3000", { headers: { "Accept-Encoding": "gzip, deflate" } })

Solution 3: Timeout Configuration

Increasing the timeout didn't help either:

cy.visit("http://localhost:3000", { timeout: 30000 })

Solution 4: Response Timeout

Adjusting the response timeout also didn't work for me:

cy.visit("http://localhost:3000", { responseTimeout: 120000 })

Hopefully, this helps someone else facing similar issues!