Cypress: Browser refreshes twice on initial load

Created on 28 Sep 2018  路  5Comments  路  Source: cypress-io/cypress

Current behavior:

When initially opening the UI using yarn cypress:open, for example, the tests start running, then the page refreshes. I made a youtube video about it:

https://www.youtube.com/watch?v=UzI5W9Lqm8A&feature=youtu.be

around 0:14 you can see the tests start running. Then at 0:18, for some reason, the browser (or iframe?) refreshes.

This causes the beforeEach hook to trigger twice, which is causing problems for me (reseeding the database twice).

One the UI is open and running, everything is fine. However, due to the beforeEach hook triggering twice, my first test run always fails.

Desired behavior:

The page should not refresh.

Steps to reproduce:

Open the Cypress interface. It seems consistent, at least on my machine.

Versions

Cypress: 3.1
MacOS: 10.13.12

Most helpful comment

This is expected behavior. When Cypress originally loads, it's on a random localhost port. Then when you cy.visit() in your test, it 're-loads' at localhost:3000, which is necessary to prevent cross-origin issues. You can prevent the 're-load' and have Cypress load directly on localhost:3000 by setting the baseUrl in your cypress.json.

All 5 comments

This is expected behavior. When Cypress originally loads, it's on a random localhost port. Then when you cy.visit() in your test, it 're-loads' at localhost:3000, which is necessary to prevent cross-origin issues. You can prevent the 're-load' and have Cypress load directly on localhost:3000 by setting the baseUrl in your cypress.json.

it worked! thanks. cypress is the best.

I was seeing a similar issue, so set baseUrl and it appears to have helped. I'm commenting as it's also worth noting this seems to have fixed my intermittent issue with users login session not always being cleared between tests.

I had the same issue though it wasn't a real problem in my case to have this duplicates; shifted to use baseUrl and they look much better now.

Thanks for raising this one.

Yep, I just ran into a similar issue where my beforeEach (which cleans the database) was running twice because of the page refresh and causing issues with my login setup.

Was this page helpful?
0 / 5 - 0 ratings