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

Add option to cy.visit() to complete on DOMContentLoaded instead of onLoad #440

Open
mkellyclare opened this issue Feb 24, 2017 · 19 comments
Labels
pkg/driver This is due to an issue in the packages/driver directory type: feature New feature that does not currently exist

Comments

@mkellyclare
Copy link

I'm testing a site that has a lot of scripts loaded on it and even though the elements I want to test for are present quickly, the test has to wait for everything on the page to load.

@jennifer-shehane jennifer-shehane added pkg/driver This is due to an issue in the packages/driver directory type: feature New feature that does not currently exist labels Mar 1, 2017
@jennifer-shehane jennifer-shehane added the stage: ready for work The issue is reproducible and in scope label Sep 14, 2018
@netusco
Copy link

netusco commented Aug 5, 2021

+1

1 similar comment
@anhaley
Copy link

anhaley commented Aug 23, 2021

+1

@darth-stewie
Copy link

This would be incredibly helpful for my tests as well - DOMContentLoaded will succeed, but window:load will not. I really would need to pass a param that would use DOMContentLoaded instead of window:load, perhaps in a window:before:load event listener

@cypress-bot cypress-bot bot added stage: backlog and removed stage: ready for work The issue is reproducible and in scope labels Oct 8, 2021
@WinstonN
Copy link

WinstonN commented Oct 8, 2021

+1

@pm-komal-jain
Copy link

pm-komal-jain commented Mar 22, 2022

+1
I am a newbie to Cypress. And trying to use it on our site that has lots and lots of blocking scripts & images which delays the onload event to trigger. If this feature - of completing cy.visit() on DOMContentLoaded event is available, it would be great.

This issue seems to be open for long, how have others handled similar situation on their end?

@AustinBernerEvercast
Copy link

@pm-komal-jain I've recently found a solution, at least for my automation project in my web app.
Cypress version 9.1.1, for some reason, plays much more nicely with my web app. I recommend giving that version a try. Do not update higher or lower version than that though, it caused me problems anyway

@pm-komal-jain
Copy link

@AustinBernerEvercast - Thanks for your response.
I did try out, using specific Cypress version 9.1.1, However, I wasn't lucky and the issue did persist for me.
I also, did try setting blockHosts property in Cypress.json to block out calls like -googletagmanager.com , www.google-analytics.com, however that wasn't of much help either, as the onload event is trigger quiet late on the website.

@AustinBernerEvercast
Copy link

@pm-komal-jain That sucks 😞
Another workaround that I've heard about but didn't have much success implementing, was manually triggering the onload event from the window object - but you'll need to modify the existing cy.visit() command in order for that to possibly work as cy.visit() is what awaits the onload event. If you can get that to work, you could build in an assertion that specifically waits for the main element(s) on your bage page to be visible. Perhaps there's something there for you to look into 🤷

@hangboss1761
Copy link

+1

1 similar comment
@BarrySaikSoundry
Copy link

+1

@meatnordrink
Copy link

meatnordrink commented Sep 22, 2022

This would be a great feature. It's currently implemented in Playwright, and has been useful recently as we've had an issue with a third-party script that's making a request that never resolves, and holds up the load event. Because of this, all of my Cypress tests have become unusable, whereas, with the company Playwright suite, we can still run them by appending {waitFor: domContentLoaded} to the Playwright equivalent of cy.visit(). (It's a pain, but at least it gives us some option.)

If anyone knows another way I can get Cypress tests to work in this situation, I'd love to be enlightened!

@tina-zeng
Copy link

+1

1 similar comment
@ffsugar
Copy link

ffsugar commented Jan 11, 2023

+1

@a8trejo
Copy link

a8trejo commented Jan 15, 2023

my current workaround is to check on the Network tab what is the last request sent by the application after loading the URL, for example https://www.heroku.com/, on the Network tab I see a GET request to https://hello.heroku.com/analytics?

So in cypress I would have a cy.intercept("**/hello.heroku.com/analytics*").as("getAnalytics") on a beforeEach hook, or at the beginning of the test, then cy.visit() and then I would have a cy.wait("@getAnalytics")

So far with that, and maybe having a cy.get("any DOM element").should("be.visible") to query the DOM until it has loaded, between those 2 tricks I have been able to get around this issue

@gvlasov
Copy link

gvlasov commented Jun 28, 2023

How hard can it be to add this essential feature? It's been requested since 2017. What is everyone testing with cypress while not having this exact problem? Is it that rare to have a long-loading resource on a page that is not critical for DOM rendering?

@a8trejo
Copy link

a8trejo commented Jun 28, 2023

Since using the approach I described above, I've never encountered this issue anymore @gvlasov

@gvlasov
Copy link

gvlasov commented Jul 18, 2023

@a8trejo I've also come up with that solution. Doing that for a script-heavy website like an e-commerce store is a huge pain in the ass, and I don't think that can be considered a viable workaround.

@PKD-2050
Copy link

PKD-2050 commented Jul 20, 2023

Hi Team I have encountered the similar issue like this when i try to click on an dropdown element within the page it gets loaded into an infinite loop. Is it causing because of this issue or it isn't working is because in Cypress, tests run in a separate frame than your application under test (AUT). The event you're waiting for will never fire inside of Cypress's document.
image

cy.get('#body_x_tabc_info_prxinfo_x_selEntity_search').trigger('click');

      cy.get('#body_x_tabc_info_prxinfo_x_selEntity_MenuItem > li').then(dropdown => {

         cy.wrap(dropdown).click();

     })

image

@ivanharalampiev
Copy link

are we waiting for a 10y anniversary for this feature request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/driver This is due to an issue in the packages/driver directory type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests