Cypress - web pages are loading slower than on a browser

Viewed 7417

I started using Cypress recently and i noticed that running a test could take 60-80 seconds, but if i go through the same UI "flow" on my browser, it takes 20-30 seconds for me to complete.

Is this normal? Are there any configurations that are affecting it?

My test is only a few lines long, using only cy.get() and cy.contains().

3 Answers

I have found that one of the causes of slowness of Cypress tests in the GUI is the list of actions unfolding in the Cypress left sidebar.

You will notice that just below the title of each test is the word "⯆ Test" with an arrowhead to its left and below it, all the actions get added as they happen. If you close that list by clicking on the word "Test" the list closes and the tests now run much faster. Now even if you close one, the next test will once more have it open.

To make the default state be closed you need a little hack in the code. As I have written elsewhere: In the file Cypress\resources\app\packages\runner\dist\cypress_runner.js look for var Hook = Object in the code. A little below that (line 102918 in version 3.8.3, line 156012 in version 4.5.0) change the isOpen field value from true to false. Your tests should now run without any slowdown.

Update for versions 6 and up:

In the same file as above, look for the string: this.state === 'failed' and change the line from:

      return Boolean(this.state === 'failed' || this.isLongRunning || this.isActive && (this.hasMultipleAttempts || this.isOpenWhenActive) || this.store.hasSingleTest);

to:

      return Boolean(this.state === 'failed' /* || this.isLongRunning || this.isActive && (this.hasMultipleAttempts || this.isOpenWhenActive) || this.store.hasSingleTest */);

Cypress test are much slower than unit test and that's normal. The difference between UI and headless run may caused by cypress initialising between command and test.

To reduce time needed to pass test avoid cy.wait(, instead use e.g. cy.get( instead.

Also you can try how long takes to run with --headless --browser chrome flags.

Cypress has to run a proxy on 3rd party browsers so that they can record the requests being sent and received. This can slow down load times considerably.

The solution I used was to run my tests in their provided electron browser. e.g.

cypress run -s [your spec file] --headed -b electron

--headed - Shows the electron window so you can know what's happening

-b electron - Use the electron browser

Related