question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress selectFile() command doesn't support .pdf files

See original GitHub issue

Current 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:open
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
anatolie-dariicommented, Jun 14, 2022

@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', }), )

1reaction
OrigoTomcommented, Jan 25, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found