Cypress not downloading file into `downloadsFolder` when app code using `window.location.href`
See original GitHub issueCurrent behavior
Current app code has an event handler that links to remote url for file download like this:
<!doctype html>
<html lang="en">
<body>
<script>
function startDownload() {
window.location.href = 'https://drive.google.com/uc?export=download&id=1GLsHhpE__lmegbaiN9QSkeXa73kXe8nx';
}
</script>
<button onclick="startDownload()">
</body>
</html>
The file will download, but it won’t go into the downloadsFolder
as specified in cypress.json
. Instead, it goes to my machine’s user’s Downloads directory (probably browser default).
Desired behavior
The downloaded file should go to the Cypress downloadsFolder
directory. My use case is downloading a file into that directory and then uploading / importing it once again.
Test code to reproduce
Using the above html snippet and calling it index.html
:
it('should download zip file into downloadsFolder config location', () => {
cy.visit('index.html')
cy.get('button').click()
})
Cypress Version
8.7.0
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Issue handling file download from cypress - Stack Overflow
I solved it with the index.js file in the plugins folder by doing the following stuff: const cypressTypeScriptPreprocessor = require('.
Read more >Test file download in Cypress | BrowserStack Docs
Learn how to test file downloads for your Cypress test running on BrowserStack. Overview. In Cypress, you can download a file from a...
Read more >Troubleshooting | Cypress Documentation
On Windows, you'll need to run the command in a command prompt terminal (not PowerShell). set DEBUG=cypress:* cypress run. If you have issues...
Read more >cypress-page-object-model - NPM Package Overview - Socket
Start using Socket to analyze cypress-page-object-model and its 0 dependencies to secure your app from supply chain attacks.
Read more >angular download excel file from web api - You.com
3.3 against 5.2.1. The latter one included a code for closing the stream in the GetAsByteArray procedure. So, I just added those lines...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@PCourteille Unfortunately no, I am using Chrome on Mac.
Hi Alessandro,
Are you in Firefox ? I struggled with the same issue for several days, but I think I finally found why.
In the file following file:
AppData\Local\Cypress\Cache\9.5.3\Cypress\resources\app\packages\server\lib\browsers\firefox.js
Part of the code is here to set the startup option for Firefox inside the “user.js” file:
AppData\Roaming\Cypress\cy\production\browsers\firefox-stable\interactive\user.js
If I correctly understand, the “user.js” file expect the path with the backslash escaped, so something like:
But the value received is already:
I’m not a developer, so I expect someone will give us better solutions, but I think we have at least two options :
Option 1:
hotfix directly in Cypress code
Inside “firefox.js”, replace the line:
by:
Option 2:
use a plugin to update the value with “\” Create a plugin, something like:
Note:
You can check the value set in Firefox with “about:config” :
I hope my answer will help you, Best regards, Paul