Reputation: 1281
I'm using cypress-file-upload in order to upload an xlsx file into a form.
I've tried 2 solutions.
// First one
cy.fixture(fileName).then((fileContent) => {
cy.get("input[type='file']").attachFile({
fileContent,
fileName,
encoding : 'UTF-8',
mimeType : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
})
})
// Second one
cy.get("input[type='file']").attachFile({
filePath : "file/path",
encoding : 'utf-8',
mimeType : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
})
With both solutions, the file is uploaded with no Cypress error, but the form rejects the file with a generic error message.
Any idea? I bet there's something about encoding but I can't find what... Thank you
Upvotes: 0
Views: 2399
Reputation: 4349
Try with the code below. Reference
Edited:
const fileName = 'upload_1.xlsx';
cy.fixture(fileName, 'binary')
.then(Cypress.Blob.binaryStringToBlob)
.then(fileContent => {
cy.get("input[type='file']").attachFile({ fileContent, fileName, mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', encoding:'utf8' })
})
Upvotes: 3