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

Downloading dynamically generated file fails when Cypress does not detect page load #14789

Closed
jimpriest opened this issue Jan 27, 2021 · 11 comments
Labels
stage: needs information Not enough info to reproduce the issue stale no activity on this issue for a long period topic: downloads ⬇️

Comments

@jimpriest
Copy link

Current behavior

Was playing around with the new download feature in 6.3.0 but that functionality seems to be targeted at simply downloading a file from a link.

I am dynamically generating a file on the server (via ColdFusion) and serving it through the browser. These are mainly reports. A user selects several 'filter' drop downs to select what data they want and then they click submit to generate a report. ColdFusion processes this on the backend and then serves the file through the browser.

See: https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-c/cfcontent.html

So in 6.3.0 I submit my form, the file is downloaded to cypress/downloads (yay) but the actual Cypress test fails while waiting for a page load which never happens.

This is also similar to #8619, #7083

Searching it seems there have been quite a few issues opened for some way to stop or intercept a page load.

Desired behavior

Once the file is downloaded have Cypress stop waiting for page load.

Versions

Cypress 6.3.0

@jennifer-shehane
Copy link
Member

Can you provide an example, html/js of a download where the page load is causing Cypress to fail? It'd be helpful for looking into the issue or creating a workaround.

Our example recipes has an example with using a form action to download a file, and that test works in that situation. https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/testing-dom__download

@jimpriest
Copy link
Author

jimpriest commented Jan 28, 2021

Looking at the testing-dom_download example it's just using a simple GET request.

CFML Example

<cfheader name="Content-disposition" value="attachment;filename=#somefile#">
<cfcontent file="#somefile#" type="application/pdf">

PHP Example

$filePath="file path here";
$filename="file name here";
header('Content-type:application/pdf');
header('Content-disposition: inline; filename="'.$filename.'"');
header('content-Transfer-Encoding:binary');
header('Accept-Ranges:bytes');
@ readfile($filePath);

Node Example

app.post('/url/to/hit', function(req, res, next) {
  var stream = fs.readStream('/location/of/pdf');
  var filename = "WhateverFilenameYouWant.pdf";
  // Be careful of special characters
  filename = encodeURIComponent(filename);
  // Ideally this should strip them
  res.setHeader('Content-disposition', 'inline; filename="' + filename + '"');
  res.setHeader('Content-type', 'application/pdf');
  stream.pipe(res);
});

I'll see if I can hack up a working example in PHP. I'm assuming these all use the same technique.

@maaaariana
Copy link

Hi @jennifer-shehane
I am also facing this issue
I can't stop cypress from waiting for a nonexistent page to load after downloading a file

@pitgrap
Copy link
Contributor

pitgrap commented Feb 17, 2021

I get the same issue with 6.5.0 and a file download via XHR (POST) and not a simple GET.
The file download works, but Cypress is waiting for a page load until timeout.

@jennifer-shehane
Copy link
Member

Can anyone provide a reproducible example that we can run completely? An HTML/JS file or a repo would be ideal. That was we can investigate.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Feb 26, 2021
@syafiqhadzir
Copy link

syafiqhadzir commented Mar 8, 2021

I get the same issue with 6.5.0 and a file download via XHR (POST) and not a simple GET.
The file download works, but Cypress is waiting for a page load until timeout.

I get the same issue with 6.6.0 & 5.6.0.

@bahmutov
Copy link
Contributor

bahmutov commented Mar 8, 2021

@syafiqhadzir Can anyone provide a reproducible example that we can run completely? An HTML/JS file or a repo would be ideal. That was we can investigate.

@jimpriest
Copy link
Author

jimpriest commented Mar 8, 2021

I cobbled this example together: https://github.com/jimpriest/cfml-cypress-download

This will spin up a Docker container running CFML and will dynamically deliver a file for download. You can see where it does download the file into the downloads folder but then Cypress hangs and never gets to the assertion/validation step and eventually times out... (page load) --waiting for new page to load--

See readme for info - simple link to a dynamically delivered file which fails in Cypress.

@ngandymov
Copy link

Hi @jimpriest , you can find a workaround here - #14857

@jimpriest
Copy link
Author

Yay. Been away from Cypress for a bit but this workaround in #14857 seems to work for me.
Thanks @ngandymov.

@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 cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 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 topic: downloads ⬇️
Projects
None yet
Development

No branches or pull requests

8 participants