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

Tests from example_spec.js don't run in Chrome after newly installed cypress #680

Closed
mcMickJuice opened this issue Sep 21, 2017 · 8 comments

Comments

@mcMickJuice
Copy link

  • Operating System: macOS Sierra 10.12.6
  • Cypress Version: 0.20.1
  • Browser Version: Chrome 61.0.3163.91

Is this a Feature or Bug?

Bug

Current behavior:

Clicking example_spec.js opens up chrome browser but no tests appear. Theres also a console.warn stating "WebSocket connection to 'ws://localhost:8080/__socket.io/?EIO=3&transport=websocket' failed: WebSocket is closed before the connection is established."

Desired behavior:

I'd expect the tests that are included in the example_spec.js would run in browser. instead, nothing appears in the browser

How to reproduce:

  • Fresh install of cypress via npm i -D cypress.
  • run node_modules/.bin/cypress open from command line
  • click example_spec.js in integration tests list
  • notice that chrome opens, however nothing ever shows up, tests aren't run
@mcMickJuice
Copy link
Author

From gitter chat:

Mike Joyce @mcMickJuice 10:37
hello, i cant get the example tests to run. after following the "installing cypress" to a T, the GUI launches and when I click on example_spec.js, chrome launches but nothing appears on the screen. there is a console.warning that states ":65417/__/#/tests/integration/example_spec.js:1 WebSocket connection to 'ws://localhost:65417/__socket.io/?EIO=3&transport=websocket' failed: WebSocket is closed before the connection is established."
can anyone help?

Jennifer Shehane @jennifer-shehane 10:39
@mcMickJuice So, we run the example tests by default on port 8080, I think I've encountered this error when I had another process running on 8080

Mike Joyce @mcMickJuice 10:39
ah ha!

Jennifer Shehane @jennifer-shehane 10:39
But, I thought that was also combined with having cypress open with a project also running 8080.

Mike Joyce @mcMickJuice 10:39
yes its launching at a different port. i'll kill whatever process is usingthat port

Jennifer Shehane @jennifer-shehane 10:39
I guess I should have opened an issue ><
Actually, that doesn't sound right either because I think we just visit the example kitchen sink at a public url.
I'll open an issue and find what was specific about it..

Mike Joyce @mcMickJuice 11:01
looks like cypress run hangs too... Timed out waiting for the browser to connect. Retrying...

Jennifer Shehane @jennifer-shehane 11:02
ok, so you're just running the example_spec.js that was generated in a new project that you installed cypress into? using npm install?

Mike Joyce @mcMickJuice 11:02
yep
same issue happening when running on 8080

Jennifer Shehane @jennifer-shehane 11:03
And you're clicking on the 'example_spec' from the GUI? What browser is selected in the GUI in the top right corner?

Mike Joyce @mcMickJuice 11:03
yep, Chrome 61
doesnt work with electron selected either

Mike Joyce @mcMickJuice 11:13
@jennifer-shehane same issue when running on node 6.x

Jennifer Shehane @jennifer-shehane 11:14
@mcMickJuice Yeah, go ahead and open an issue with as much detail as possible. I'm not able to replicate this exact behavior with a fresh install running in Chrome 61. I have seen the websocket error though, so there is some edge case that we're missing that we need defined.

@jennifer-shehane
Copy link
Member

I was unable to replicate this exact behavior, but I have seen the WebSocket connection error before in a strange edge case where I had Cypress open in 2 projects with the same baseUrl set on both to localhost:8080, I'm unfortunately unable to replicate this again though.

@mcMickJuice
Copy link
Author

This was an issue with my hosts file. I had 127.0.0.1 mapped to a url that mapped to docker but not to localhost. After adding localhost to map to ip4, everything worked!

@Nopik
Copy link

Nopik commented Oct 4, 2017

I'm having similar error. My app when started tries to do some websocket connections (which is actually webpack's dev server hot loading feature), but occasionally those fail (the handling on the server side for this is more convoluted). Anyway, the effect is that app tries to open ws connection and server listens on proper port, but does not support http upgrade at that moment, so server drops connection. Cypress immediately seeing it kills itself, too, without even trying to run anything else, even if I have cy.wait(20000).

@brian-mann
Copy link
Member

@Nopik we need a reproducible repo / issue opened to look at this. As it is right now Cypress runs on tons of projects with websocket connections so there is likely a deeper issue at hand. Would need some direction for us to be able to look at it.

@2fat2kidnap
Copy link

2fat2kidnap commented Feb 9, 2018

So I had the same issue: launching a Cypress test would open both the Chrome and Electron browser, but nothing would happen, their pages would remain blank.
In the Chrome console, I would see that the Websocket connection could not connect, as the WebSocket would close before the connection would be established.

Turns out that the problem was that for some reason, obscure to me, and almost certainly completely unrelated to Cypress, my hosts file on macOS got removed. That meant that the routing of localhost -> 127.0.0.1 got nuked, and Cypress relies on this mapping. It launches the browser with the assumption that it will find the test runner at localhost, which should be at 127.0.0.1 of course, in most cases anyways.

In short, if you're seeing this, maybe check your hosts file just in case?

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Feb 12, 2018
@Mipme
Copy link

Mipme commented Mar 23, 2018

Wow, well - the obvious is not always the obvious.

My story in short:
On my Mac I got the hosts.prefPane installed, so I can map lots of URLs to my local development server. Turned out I had to insert a mapping from 127.0.0.1 to localhost to get cypress running.
This, although typing localhost or 127.0.0.1 always returned me the default index page in the Sites folder!

Thx for the fix!

@saas2813
Copy link

I got logs similar to these. The problem was that my

/etc/hosts

file did not include a line:

127.0.0.1 localhost

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Jul 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants