-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 cannot access different ports on localhost #26154
Comments
Hi! You code looks good, Happy to try and run your code and debug it, I think the repository is private. Can you make it public? Thanks! |
Hi @lmiller1990 ! Thank you for your response. The repository should now be publicly available. By now, I have tested the solution with a non-localhost database server, which works completely fine. However, the issue still persists locally. I am highly interested in seeing whether you can recreate the issue! |
@tristantill another question - I can see the repo now. Is there a specific branch? I can't see the see Can you share the exact steps to reproduce? Eg, what commands to run in which directories? I can probably figure it out, but it'll be likely faster if you just tell me exactly what to do. |
I also confirm that. If you use different ports for localhost it accepts only one. the workaround is to set the domain name in the OS hosts file. an example for windows: |
@lmiller1990 sorry for the inconvenience once again. The current branch I am running is the latest version of the main branch. The code I tested was with the "basic installation" of Cypress (getting started in the cypress documentation): The spec.cy.ts is as kept as simple as possible for testing. The file itself contains no other statements than these: The issue prevails if 'Load frontend' and 'Load backend' are swapped (as seen in the screenshots). Thank you @szykov for the workaround, this solution works perfectly fine for me as well! |
Interesting, I tried to reproduce in a minimal fashion, but I was actually able to visit the different ports: My minimal reproduction: /// <reference types="cypress" />
describe('page', () => {
it('works', () => {
cy.visit('http://localhost:7777/foo')
cy.contains('FOO')
})
it('works again', () => {
cy.visit('http://localhost:8888/bar')
cy.contains('BAR')
})
}) App 1: const express = require('express')
const app = express()
app.get("/foo", (_, res) => {
res.send(`<div>FOO</div>`).end()
})
app.listen(7777, () => console.log('Listening')) App 2: const express = require('express')
const app = express()
app.get("/bar", (_, res) => {
res.send(`<div>BAR</div>`).end()
})
app.listen(8888, () => console.log('Listening')) |
Repo: https://github.com/lmiller1990/cypress-test-tiny/blob/issue-26154/cypress/e2e/spec.cy.js ( Could this be windows specific? Another user has a similar problem here, as you pointed out: #6475 |
Happy to reopen once we've got more information to continue debugging. Until then, I'll close this, since I don't see any actionable work in Cypress relating to this issue. |
Hello, I had the same issue in one of the two projects I work on with Django and Angular. Turns out I was using --host 0.0.0.0 on the one that was working ok. I run the angular server like this and the problem was solved
|
Worked for me. Had to use |
Reproduced on windows, only appeared after updating to Node 18.17.1 from 16.20.2. In this case it was accessing MFE remotes, and had to change NX web:file-server to listen on 0.0.0.0 as suggested in the other workarounds |
Same here after updating to Node 18.17.1 (on Mac M1). We have a NextJS frontend running on http://localhost:3000 and then our GraphQL server running on http://localhost:4000. What is very weird is that running
and running Any clue? |
See this |
I had the same issue on mac. For me the solution was to set IPv6 to local-link only. After I restarted all servers, it worked. |
The problems mostly arise if the dev server is not listening on both IPv4 and IPv6 stacks and after migrating to Node.js >= 18 where the order of IP addresses returned from Node.js requesting the address of |
I just changed from http://localhost:8888 to http://127.0.0.1:8888 and it worked for me |
I have the exact same issue as @scailancrei . If I do a API request to login to my application, it does not work. If I visit the login page via the UI, it works. Angular: 18 |
Exact same problem here too. Any tentative to reach the API from cypress' controlled browser doesn't work, but if I open a regular browser, it does. I changed my api url from |
Please, is there any workaround for Laravel and Vue? This is really frustrating. It should be reproducible from this repo I prepared: https://github.com/patmull/laravel_vue_cypress_minimal (.env files used are in the README). Assuming installed PHP 8.3.14 and NPM 10.9.0, my tested OS is: Fedora Linux 41 KDE Plasa 6.2.4.:
Full ("normal") browsers are OK. Cypress fails with CORS (Cross-Origin). For example for Firefox 133.0: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/sanctum/csrf-cookie. (Reason: CORS request did not succeed). Status code: (null). On URL: localhost:8000/sanctum/csrf-cookie When I tweaked around with my full repo, it was OK on sanctum/csrf-cookie, when I changed every env variable of localhost:8000 to 127.0.0.1:8000, however then my other requests (e.g. /login /register, etc...) got blocked because of the different origin. It may be either related to new version of either Cypress or npm or something else, or PHP server config. I tested this app previously on Ubuntu 22.04 without any issue on Local. Cypress testing also works on custom local domain or NGINX server with real domain, but not on localhost. Unfortunatelly, I had no time to test it on different OS yet. I am shooting in the dark but I also include my /etc/hosts in case problem is here:
|
On Windows, I followed Method 2 (netsh commands) described here. That is working for now for me. The reason I used that is because the MFE framework at my current company doesn't allow for setting the webpack dev server host option right now. This could just be disconnect between how webpack/node.js and cypress/browsers resolve names. |
Current behavior
A similar issue has been closed previously (#6475) without a working solution in place.
I am trying to implement e2e tests for a web application with an AngularJS frontend and a Django backend with Cypress. Both run locally (frontend: localhost:4200, backend: localhost:8000), but either one or the other are not accessible in the Cypress environment, despite working perfectly fine in a regular browser window. This is happening regardless of which (Cypress) browser I am using. In each case, the domain I access first manages to load with the other being blocked:
Desired behavior
Cypress should be able to reach both ports on localhost
Test code to reproduce
The code for both backend and frontend are available at https://github.com/ChriReiter/JAM
The running config uses an external database server, which is no longer in use. To redirect requests to the localhost, change the file at frontend/src/environments/environments.ts to target the localhost as the apiBaseUrl
Cypress Version
12.8.1
Node version
18.12.0
Operating System
Windows 11, Version 22H2
Debug Logs
Other
No response
The text was updated successfully, but these errors were encountered: