Add support to get downloaded file when its name is not known.
See original GitHub issueIt would be useful to have an option to parse downloaded files when their name is not known at the moment of download. I tried to create a helper function (task) for that which returns the latest file, however, it’s not reliable as it’s executed when file is not there yet:
// plugins/index.js
const getLastDownloadFilePath = () => {
const dirPath = 'cypress/downloads';
const filesOrdered = readdirSync(dirPath)
.map(entry => path.join(dirPath, entry))
.filter(entryWithPath => lstatSync(entryWithPath).isFile())
.map(fileName => ({ fileName, mtime: lstatSync(fileName).mtime }))
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
return filesOrdered.length ? filesOrdered[0].fileName : false;
};
I believe it may be useful to have the ability to:
- wait for file download,
- get the name of the downloaded file.
These two should allow handling such cases.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Cypress identify the downloaded file using regex
When I have the downloadedFilename as 'ABCDEF.txt', it works fine [I have hard coded here]. But I need some help to get the...
Read more >Error message when you open or save a file in Microsoft Excel
In Microsoft Office Excel 2007, you may receive the following error message: '<Filename>.<extension>' could not be found. Check the spelling of the file...
Read more >Validate Downloaded file after clicking on downloaded button
It is very important to verify if the file is downloaded successful or not. Most of the cases we just concentrate on clicking...
Read more >Print and download file name not same as saved filename
Have a little issue that it getting in the way When I print a ... Anyone know how to mod the current scrip...
Read more >Naming Dropbox files and folders
Even if you don't get an error message when you name a file on your operating system, if you don't follow the guidelines...
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 Free
Top 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
There’s an example of reading a file directly after download by looking for extension. Is this helpful? https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__download/cypress/integration/spec.js#L263
@viktorgogulenko thanks for that, that should work when the file is generated in the backend and later sent in the response. Unfortunately, in my case, the file is generated by frontend code with
file-saver
library. Therefore there’s no additional request with a filename in it.I managed to create a workaround with:
and in test, I use it with
wait-until
plugin: