Cypress selectFile() command doesn't support .pdf files
See original GitHub issueCurrent behavior
After doing the upgrade to v9.3.1 I migrated to selectFile()
using the migration guid.
After finishing the migration I found that selectFile()
command is working with .png
and .jpg
but it’s not working with .pdf
files. “knowing that the path is correct as I prefixed the path with cypress/fixtures/”
It doesn’t throw any errors, but the uploaded file is corrupted. it keeps loading forever when I click to preview it
FYI: I tried uploading the .pdf
manually and it works but not with cypress automation
Desired behavior
Should be able to upload .pdf
files
Test code to reproduce
cy.get("#myInput").selectFile(pdfPath);
Cypress Version
9.3.1
Other
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
selectFile - Cypress Documentation
Selects a file or files in an HTML5 input element or simulates dragging a file or files into the browser. It is unsafe...
Read more >How to upload an PDF file with cypress.io - Stack Overflow
The idea will be to go and find the pdf file into my directory. I didn't find some way yet. This is the...
Read more >How to upload a file in cypress - TestersDock
selectFile() command. This was introduced with cypress v 9.3.0. a) File upload using the default 'select' mode – By default, .selectFile() runs ...
Read more >Cypress 9.3.0 added .selectFile() command to select files
However, since it's a relatively new package, it also has multiple limitations and one of those is that it doesn't support native file...
Read more >Part 12 - File Uploads with Cypress - YouTube
In this video I've shown: -1. How to enable file upload support in Cypress2. different elements (input type= file | drag drop file...
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
@cheukribbon @khashaba in case you guys still have issues I managed to make it work by doing this:
cy.fixture('myFile.pdf', null) .then(Cypress.Buffer.from) .then(contents => cy.get('.file-input') .should('be.enabled') .selectFile({ contents, fileName: fileName, lastModified: Date.now(), mimeType: 'application/pdf', }), )
We have been experiencing similar issues trying to upload .txt and .csv files.
It would be really useful if Cypress were to document which filetypes are supported by selectFile().
The documentation is only explicit to .JSON, .png and .jpeg.