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

Cypress loads page twice on first visit, even if baseUrl is set #15523

Closed
maximedupre opened this issue Mar 16, 2021 · 11 comments
Closed

Cypress loads page twice on first visit, even if baseUrl is set #15523

maximedupre opened this issue Mar 16, 2021 · 11 comments
Labels
stage: needs information Not enough info to reproduce the issue stale no activity on this issue for a long period

Comments

@maximedupre
Copy link

maximedupre commented Mar 16, 2021

Current behavior

When calling npx cypress open and running the test for the first time (those two conditions are needed to reproduce), the page is loaded twice on the first cy.visit. I have added a console.log in my index.html and can clearly see that this one call of cy.visit makes the html load twice.

This issue suggests that this behaviour can be avoided by setting a baseUrl in the cypress.json, but that is not the case - there might be a regression bug. This is my cypress.json:

{
    "baseUrl": "http://localhost:3031",
    "screenshotOnRunFailure": true,
    "video": true
}

I don't have Chrome installed on my machine currently, so it's using Electron to run tests.

Desired behavior

index.html should not be loaded twice on first call to cy.visit

Versions

Using v6.7.1

@jennifer-shehane
Copy link
Member

Do you have an example of the test code?

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Mar 16, 2021
@maximedupre
Copy link
Author

Thanks for the response.

Just the most minimal test code causes the problem:

describe('Navigation', () => {
    it('should only fetch the user once when visiting multiple pages that need the user', () => {
        cy.visit('/').then(() => console.log('cy.visit has resolved'));
    });
});

As you can see by the following screenshot, index.html is loaded twice after one call to cy.visit.

Screen Shot 2021-03-17 at 9 23 43 AM

@yann-combarnous
Copy link

Same behavior for us

@todd-m-kemp
Copy link

This might be the same thing (or perhaps just related) that I reported back in January? #14538

@maximedupre
Copy link
Author

maximedupre commented Mar 22, 2021

I don't think so, since my use case doesn't involve changing domain during the test. Your behaviour might actually be the expected behaviour (see #2542) (don't quote me on this :D).

@maximedupre
Copy link
Author

@jennifer-shehane :D

@svalluri-cais
Copy link

Adding baseUrl will resolve the problem. If your base url is inside env: { baseUrl : "blah blah"} this won't work. It has to be like baseUrl: "blah blah" inside cypress config file

@Troyc-boop
Copy link

I have the same problem. I added the baseUrl and it was ok but now I am running the tests against the app that is running on my local machine. I changed the baseUrl to go to the new site (which is now local) but now it loads the first visit() twice. The only thing that is changed is the baseUrl because now I build the app that I am testing locally. Could that be the problem?

@Troyc-boop
Copy link

I have the same problem. I added the baseUrl and it was ok but now I am running the tests against the app that is running on my local machine. I changed the baseUrl to go to the new site (which is now local) but now it loads the first visit() twice. The only thing that is changed is the baseUrl because now I build the app that I am testing locally. Could that be the problem?

I found the solution. The problem was that when I changed the URL I was still using HTTPS as it was before but there was no self-signed certificate or cypress couldn't find it (the app is running in docker) and that is the reason why it would start 2 times at the beginning of each spec file as when you use only cy.visit() withouth baseUrl. The reason for this is that cypress creates its one self-signed certificate and restarts again with the certificate. The solution was to use HTTP.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs information Not enough info to reproduce the issue stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests

7 participants