https://cypress.io logo
How can I avoid "waiting for page load" after clic...
# i-need-help
f
I have a test where I download a PDF file through a button. The button simply downloads the file, no reload, no prompt, nothing. For some reason, when I click this link, the file is downloaded (I can see it on my downloads folder) but the test keeps waiting for Page to Load, when nothing is actually loading. Since the page did not trigger the load event, my test times out after 60 secs. The problem is that, as mentioned, nothing is loading. no resources or anything. Why is it waiting for page to load, or how can I avoid/interrupt this validation?
btw, I've seen this problem posted many times, but no solutions. It i strange that there is nothing I can trigger to just skip it.
n
you probably trigger some API call after you click on the button. So before the click you could intercept that call and wait for it to return some response or status code. For example in my case I have 2 calls when downloading doc in my app, one is the post request to request the download, second one is the get request that happens each second that checks is the doc ready or not. So I check for the second one
f
Thanks, where exactly do you add that intercept? Do you wrap the click event there? cause my problem is that after I click, it just starts waiting for the page to load, so it doesn´t continue.
n
after you manually find which call is responsible for the download you could try something like this.
Copy code
cy.intercept('**/getExportFile/**').as('export'); // your call responsible for the export
        clickDownloadButton(); // your button click

        cy.wait('@export', {timeout: 60000}).then(() => { // I increased timeout for this call since it can take more time then other calls
            // assert whatever you want
            });
also remove that wait for the page to load, not sure what is that
f
oh I see, I will try that.
wait for the page to load, is native cypress. It waits for the page to fire a 'load' event. I can't control it or skip it. Apparently it is a very big bug that has been around for years
and what people is doing, is reducing the timeout to pretty much nothing, and then handling the error.
h
Hey @faint-ocean-92094 did this solution work for you? I'm having the same issue
51 Views