Cypress: Cypress hangs on various Docker images and with very little executing

Created on 16 Apr 2020  路  13Comments  路  Source: cypress-io/cypress

Preface:
Per the title, this has only been an issue when running in a Docker Container, or in a CI/CD platform like Gitlab. Running it on my Mac OS X (10.15.4 ) leveraging yarn add cypress and running tests locally (yarn cypress run) in the CLI or on the console (cypress open) _work_. That is what makes this issue SUPER strange and hard to debug.

Issue:
I have used /included:4.X versions, base:10, as well as browser node/chrome version. Just focusing on one for this issue to make it easier let's focus on: cypress/browsers:node10.16.0-chrome77

No matter what I put after cy.get('a.card').first().click() Cypress hangs indefinitely. The longest I have waited was 1hr. No crash, no logs, just hangs.

Since I have used so many versions I can only assume I am doing something wrong, but this is the only test/spec I am running and it works fine outside of any containerization. I have spend days trying to get over this hump.

So, an example problem is....

cypress/browsers:node10.16.0-chrome77

and running

yarn cypress run --headless --browser chrome
````

on the following spec in a cypress image, which works unless I add the last line, then it hangs. 

```js
describe('Check Basic Access', function () {
  it('Login and Edit', () => {
    cy.visit(`${Cypress.env('SITE')}/logout`)
    window.localStorage.setItem('first-time-dashboard', false)
    cy.get('input[placeholder=Email]').type(Cypress.env('UNAME'))
    cy.get('input[placeholder=Password]').type(Cypress.env('PW'))
    cy.get('button[data-smc=Button]').click()
    cy.get('a.card').first().click() <----- This line hangs up the system without error
  })
})

The hard thing to convey here is the hundreds of variations I have tried with routes, waits, contains, browsers (Electron 80, and Chrome77-80), and the various results between memory faults and non--informing hangs.

For example:

If I give that a timeout like this using Electron:

cy.get('a.card', {timeout: 7000}).first().click()

I get an error like this:

[4262:0416/071201.991156:FATAL:memory.cc(22)] Out of memory. size=69455872

With Chrome 80 it just hangs.

Also, note, I have verified that the page and class selector do exist on the page, and verified it is visiting the correct page (using cy.screenshot()), and it works in the console every time (ex cypress open and run from there.)

With so little code, and my clean use of the image, and the fact that it works on my Mac env, I can't imagine what I am doing wrong......

One thing that may help is getting the logs on the left of the console to show up on the CLI?

Screen Shot 2020-04-15 at 11 50 18 PM

I can't seem to find a way to get that same info in my CLI terminal. (Note: I _don't_ want console.logs from the browser, just the step-by-step info on what Cypress is executing.)

Any help to get over this hanging/memory issue would be _much_ appreciated.

needs information

All 13 comments

The cypress-failed-logs plugin prints the step-by-step info for failed tests to the terminal output. That may or may not be helpful since it sounds like the tests are hanging versus actually failing.

Yes, was going to point out also that this plugin will print Cypress commands on failure, but I believe the test would have to actually fail: https://github.com/archfz/cypress-terminal-report

So what is functionally happening when this anchor link is clicked in your application. Like, what normally happens when someone clicks this anchor link? Is it navigating away somewhere? Do you have any before:unload handlers in your app or anything? The behavior of the app is likely a key piece of info here that we need.

Could you run Cypress in debug mode mode and print the entire set of logs here?

I also get an 'Out of memory error' and I am very interested in a solution. Most of the time my test finishes after 3 minutes, but sometimes it 'hangs' and I could not determine what the problem is because the test runs into the timeout and creates a broken video. I run the test in a cypress chrome Docker container with GitHub Actions.

[0418/130705.890866:FATAL:memory.cc(22)] Out of memory. size=262144 +2s

Thanks for the responses all.
@jennifer-shehane, it may help to note that it is a Single-Page application. After login, an API request is made to load information on the dashboard. Once a "card" is loaded, it tries to click it. I am not sure if it gets that far (passed login) or hangs up when clicked.

@jannnik yup same. For me, whether it hangs or gets a memory issue _seems_ to be based on the selection of the browser. What is weird is it use to work, and to try and fix I have trimmed back all the code save those few lines I mentioned above.

馃 馃敨 ugh....

Not sure if it's the same issue described here but for me Cypress was hanging when visiting a mis-configured HTTPS server within Docker Compose. It was very hard to diagnose because there was no logging or timeout and not reproducible on localhost where HSTS was not enforced.

@ncjones would some of the tests pass before the hang? Can you elaborate on what was misconfigured?

Similar experiences here (jenkins pipeline in OpenShift container environment). My impression is that failing tests make cypress hang.

Have experience similar issue (testing React web application) once running local docker container from cypress/browsers:node12.16.1-chrome80-ff73.
It might be related to what @sshadmand mentioned up above (Single-Page application).
Same test are runnining properly on local machine both in headed and headless mode.

Running Docker on Windows 10.

Have experience similar issue (testing React web application) once running local docker container from cypress/browsers:node12.16.1-chrome80-ff73.
It might be related to what @sshadmand mentioned up above (Single-Page application).
Same test are runnining properly on local machine both in headed and headless mode.

Running Docker on Windows 10.

Resolved this by adding shm_size: '256m' to the docker-compose.yml

Try workarounds for passing --disable-dev-shm-usage https://on.cypress.io/continuous-integration#In-Docker

@dalinarkholin Sorry I missed your message. No tests were passing because Cypress could not communicate with the Expo dev server. The fix was to remove the "--no-https" Expo CLI arg and add the "SSL_CRT_FILE" and "SSL_KEY_FILE" environment variables. Expo was then launched with yarn expo web --no-minify. Expo version is 37.0.3 and Expo CLI version is 3.18.6.

@ncjones Were the environment vars "SSL_CERT_FILE" and "SSL_KEY_FILE" for Cypress or for Expo?

@stuarth-inova those are expo environment variables.

Was this page helpful?
0 / 5 - 0 ratings