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

https://cypress-realworld-testing-course-app.vercel.app/
72 stars 225 forks source link

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

Closed DanielDaCosta closed 1 month ago

DanielDaCosta commented 1 month ago

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

DanielDaCosta commented 1 month ago

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!