Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress can't access different ports on same domain #6475

Closed
mankinchi opened this issue Feb 16, 2020 · 14 comments
Closed

Cypress can't access different ports on same domain #6475

mankinchi opened this issue Feb 16, 2020 · 14 comments

Comments

@mankinchi
Copy link

mankinchi commented Feb 16, 2020

Current behavior:

What I have is 2 tests (initially 1) looks like this

Application port (1):
Screen Shot 2020-02-17 at 10 14 28 am

Authentication port (2) (previously is going straight to the website and fill it in, but I switch to use cy.request instead):
Screen Shot 2020-02-17 at 10 14 31 am

Additional code:
Screen Shot 2020-02-17 at 10 15 41 am

So if I put (1) before (2), this error shows up:

CypressError: cy.request() failed trying to load:

http://localhost:8888/login

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: connect ECONNREFUSED 127.0.0.1:8888

-----------------------------------------------------------

The request we sent was:

Method: POST
URL: http://localhost:8888/login

-----------------------------------------------------------

Common situations why this would fail:
  - you don't have internet access
  - you forgot to run / boot your web server
  - your web server isn't accessible
  - you have weird network configuration settings on your computer

The stack trace for this error is:

RequestError: Error: connect ECONNREFUSED 127.0.0.1:8888
    at new RequestError (/Users/tringuyen/Library/Caches/Cypress/4.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/errors.js:14:15)
    at Request.plumbing.callback (/Users/tringuyen/Library/Caches/Cypress/4.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/plumbing.js:87:29)
    at Request.RP$callback [as _callback] (/Users/tringuyen/Library/Caches/Cypress/4.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at self.callback (/Users/tringuyen/Library/Caches/Cypress/4.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/request/request.js:185:22)
    at Request.emit (events.js:203:13)
    at Request.onRequestError (/Users/tringuyen/Library/Caches/Cypress/4.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/request/request.js:877:8)
    at ClientRequest.emit (events.js:208:15)
    at Socket.socketErrorListener (_http_client.js:399:9)
    at Socket.emit (events.js:203:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at processTicksAndRejections (internal/process/task_queues.js:77:11)

And if I put (2) before (1), this error shows up:

    CypressError: cy.visit() failed trying to load:

http://localhost:8000/

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: connect ECONNREFUSED ::1:8000

Common situations why this would fail:
  - you don't have internet access
  - you forgot to run / boot your web server
  - your web server isn't accessible
  - you have weird network configuration settings on your computer

The stack trace for this error is:

Error: connect ECONNREFUSED ::1:8000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14)

Desired behavior:

Accessing both ports doesn't end up with error

Test code to reproduce

  • Create 2 different ports using PHP (8000, 8888)
  • Have cypress try to access both of them

Versions

Cypress: 4.0.2
Mac: 10.15.2

Additional

I found a similar issue here: https://stackoverflow.com/questions/60031340/cypress-login-command-with-cy-request-causes-subsequent-cy-visit-to-fail

@jennifer-shehane
Copy link
Member

I'm not able to recreate this. I have 2 local servers running and there are no errors accessing them. I even added the extra config options although I think it's unnecessary. Tried cypress run and cypress open.

Can you access the domain normally, via curl within your environment? What is the result of running curl yourdomain.com? Can you access the domain via a normal Node http.request within the environment? Knowing the results of these will help narrow down if this is a network issue inside or outside of Cypress.


Code I ran:

it('visit', () => {
  cy.visit('http://localhost:2222', {
    failOnStatusCode: false
  }) 
})

it('request', () => {
  cy.request({
    method: 'POST',
    url: 'http://localhost:8080',
    form: true,
    followRedirect: false,
    body: {
      username: '',
      password: ''
    }
  })
})

Screen Shot 2020-02-18 at 12 42 15 PM

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Feb 18, 2020
@mankinchi
Copy link
Author

mankinchi commented Feb 18, 2020

hi @jennifer-shehane , thanks for your reply.

  1. I'm not using Node to build this application so I can't try http.request
  2. This is the result of curl localhost:8000
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='../login?returnURL=%2F'" />

        <title>Redirecting to ../login?returnURL=%2F</title>
    </head>
    <body>
        Redirecting to <a href="../login?returnURL=%2F">../login?returnURL=%2F</a>.
    </body>
</html>%    

And this is of curl localhost:8888

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='/login?returnURL=%2F'" />

        <title>Redirecting to /login?returnURL=%2F</title>
    </head>
    <body>
        Redirecting to <a href="/login?returnURL=%2F">/login?returnURL=%2F</a>.
    </body>
</html>%                                                                                                                     

They might look similar but they are different.

  1. When I run the test, I have tried to open a new tab in the browser controlled by Cypress and put the url in. It resulted in the same error. Doing this with my normal Chrome browser yield no error

@Sumedh-k
Copy link

Do you see anything different in the server logs when Cypress is running the tests?

also try http://127.0.0.1:8888

@mankinchi
Copy link
Author

@Sumedh-k the request never reaches my server :( so nothing is shown on the error server. 127.0.0.1:8888 actually works, but since 127.0.0.1 and localhost are being treated as 2 separated domain, cookies are not being set correctly

@jennifer-shehane
Copy link
Member

@mankinchi Are you behind a corporate proxy? Do you have any proxy configuration set up? https://on.cypress.io/proxy-configuration

@mankinchi
Copy link
Author

@jennifer-shehane I am not using any proxy nor connecting to any proxy in my company

@mankinchi
Copy link
Author

Is there any update on this?

@cypress-bot cypress-bot bot added stage: needs investigating Someone from Cypress needs to look at this and removed stage: needs information Not enough info to reproduce the issue labels Mar 16, 2020
@jennifer-shehane
Copy link
Member

Since this issue hasn't had activity in a while, we'll close the issue until we can confirm this is still happening. Please comment if there is new information to provide concerning the original issue and we'd be happy to reopen.

@jennifer-shehane jennifer-shehane removed the stage: needs investigating Someone from Cypress needs to look at this label Apr 8, 2022
@VenatusSimpleX
Copy link

VenatusSimpleX commented Jul 26, 2022

Hi, I can confirm that it still doesn't work...

Port 8080 is running, viewable in normal browser/postman:
image

Not viewable in cypress browser (chrome):
image

Says that connection refused, even though it can be accessed elsewhere that isn't cypress:
image

For context, the frontend and backend are two different projects, hence the 8000 and 8080.

@Sergiobop
Copy link

Sergiobop commented Aug 31, 2022

Happens to me too

It there any workaround?

I have an angular app, and a laravel backend (localhost:4200 and localhost:8000)
When i try to run the e2e, the backend is not accessible as @VenatusSimpleX said

@jennifer-shehane

@lmiller1990
Copy link
Contributor

I am trying to help another use debug it here: #26154 (comment). I couldn't make a minimal reproduction, but the user there suggested a work around when they encountered this issue. I wonder if it's windows specific?

@josephkabba
Copy link

I am using fedora 35 and am also have the same issue

@lmiller1990
Copy link
Contributor

Take a look at #26154 @josephkabba. Can you provide a minimal reproduction? You could share it there.

@josephkabba
Copy link

Thanks @lmiller1990 #26154 helped solve the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants