can cy.writeFile write any type of document?
See original GitHub issueCurrent behavior:
After a download attempt an excel file with cy.request()
command, response.body
can be saved by using cy.writeFile
command with any filename and extension (like ‘text.xlsx’) but file cannot be open.
Desired behavior:
Any type of file should be saved with any extension and can be opened properly.
Versions
Cypress: 3.0.1 Operating system: Mac Browser : Electron 59
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (3 by maintainers)
Top Results From Across the Web
writeFile - Cypress Documentation
cy.writeFile() requires the file be successfully written to disk. Anything preventing this such as OS permission issues will cause it to fail.
Read more >Can I use cy.writeFile() to write a formatted txt file?
No, .txt files generally do not have bold formatting, but you could use an HTML file.
Read more >How to use writeFile and readFile in Cypress? - TestersDock
In this article, we will learn to use write File (write to a file) and readFile (read from a file) in cypress.
Read more >How do I write to a file in Cypress? - YouTube
Chapters. View all · Introduction · Introduction · Introduction · CY WRITE - Storing data in a JSON File. · CY WRITE -...
Read more >Files | Cypress examples (v9.0.0) - Gleb Bahmutov
To write to a file with the specified contents, use the cy.writeFile() command. // https://on.cypress.io/writefile // You can write ...
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
@WesleySSmith thank you very much, this idea helped me to create a workaround. Maybe I put it here, just in a case someone needs it, too:
plugins/index.js:
support/commands.js:
In my test file:
My
plugin/index.js
contains a bit more code, because I need to parse response headers in order to get correct PDF filename.Also, I reported this issue in a separated task: https://github.com/cypress-io/cypress/issues/3576 So it’s already approved and marked as a bug and hopefully we won’t need to use such workarounds soon 🙌
I am having a similar issue here, except that I am dealing with zip files.
The logged response.body.length (50505) is of different value from the original file size on the server and the content-length header (53398) in the response. If I manually download the zip file using another web browser, the saved file can be opened correctly.
I suspect cy.request is performing some post-processing on the response body, even though the response’s content-type is set to application/zip. I have repeated the same test a number of times; the response.body.length is always the same length, so it is clearly not a network issue.