Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress long automation script crashes the Chrome browser with Aw Snap Error

I am having a browser crash problem in cypress. My automation script is somewhat long process and due to which after it runs couple of scenario. Everytime when it tries to run the third scenario the browser crashes and shows the below screen.

enter image description here

and some times it gets timeout and throws 440 unknown code error.

enter image description here

If I move my 1st scenario then also the same behaviour. Everytime 1st and 2nd executes perfectly but from the 3rd all tests fails.

Does anyone face the similar kind of issue?

like image 839
Prashant Kankhara Avatar asked Dec 04 '22 19:12

Prashant Kankhara


1 Answers

Cypress has two running modes: debugging/development mode, started with cypress open, and a test running mode, started with cypress run.

cypress run has a few key differences from cypress open. The most obvious one is that cypress run is headless. It starts an Electron browser in the background and performs all your tests.

This is not the only difference. When running with cypress open, Cypress takes regular DOM snapshots for debugging purposes, as you are probably aware. This is implemented with what has been described as a controlled memory leak; if you have a single test that runs for too long using cypress open, the memory will continue to climb until Chrome eventually crashes.


If your tests work fine with cypress run and not with cypress open, then your issue is very likely memory. If this is the case, you have two options which can help.

First, you can reduce the number of snapshots kept in memory. Your cypress.json file in your root Cypress folder allows you to set custom values for various settings. numTestsKeptInMemory defaults to something like 30, but you can reduce it to 10, 5, or even 0. At 0 you will not get any DOM snapshots. The memory usage will still climb, but it will climb at a much slower rate.

{
    "numTestsKeptInMemory": 0
}

Second, you can and should split your one large test file into multiple smaller test files. As of version 3.0.0, Cypress runs each test file in its own render process. This allows Cypress to clean up after each test, effectively fixing the memory issue as long as your individual files are small enough.


If neither of these fix your issue then you may be dealing with another bug, such as this one. If you cannot find your issue on the Github tracker, you may want to consider reporting it.

like image 137
Joshua Wade Avatar answered Dec 06 '22 19:12

Joshua Wade