Cypress-file-upload: [Feature] Add support for xls file types.

Created on 2 Sep 2019  Â·  7Comments  Â·  Source: abramenal/cypress-file-upload

Desired behavior:

Our website requires up to be able to import excel spreadsheets as part of its functionality, is this something which could be added?

enhancement

Most helpful comment

@jdcl32 Thanks for your input with only a small bit of editing I was able to successfully import using cypress

cy.fixture(fileName, 'binary') .then(Cypress.Blob.binaryStringToBlob) .then((fileContent: any) => { cy.get('#__BVID__243').upload({ fileContent, fileName, mimeType: 'application/vnd.ms-excel', encoding: 'utf8' }, { subjectType: "input", subjectNature: "dom", force: false }) });

I had to use the next argument to set the processing options as without the code would not run.

Thanks for your help with this, I am now able to successfully upload excel files using Cypress. :)

All 7 comments

Hi @harrison9149
Thanks for submitting the issue!

I think there might be some issues in cypress itself, see: https://github.com/cypress-io/cypress/issues/1558
Generally if you can use xls within cy.fixture it is also possible to do with this plugin.
It might be necessary to put specific encoding property (with same value as for cy.fixture).

@harrison9149 We needed to test spss files upload and this is how I got it to work:

cy.fixture(fileName, 'binary')
  .then(Cypress.Blob.binaryStringToBlob)
  .then((fileContent) =>
       cy.get('.file-input').upload({
           fileContent,
           fileName,
           mimeType: getMimeType(fileName),
           encoding: 'utf8'
       })
);

Setting the encoding as utf8 on the plugin will pass the fileContent as it is, and since we are passing a binary blob it works as expected. Maybe that will help you with xls files as well

@jdcl32 Thanks for your input with only a small bit of editing I was able to successfully import using cypress

cy.fixture(fileName, 'binary') .then(Cypress.Blob.binaryStringToBlob) .then((fileContent: any) => { cy.get('#__BVID__243').upload({ fileContent, fileName, mimeType: 'application/vnd.ms-excel', encoding: 'utf8' }, { subjectType: "input", subjectNature: "dom", force: false }) });

I had to use the next argument to set the processing options as without the code would not run.

Thanks for your help with this, I am now able to successfully upload excel files using Cypress. :)

Hi @harrison9149
Thanks for submitting the issue! I am happy that it is resolved now.
Anyway you spotted a bug here – it is true that processing options are optional and could be omitted. I am opening a PR to fix this.

And shout out to @jdcl32 for helping with this!

@all-contributors add @harrison9149 for bug

@abramenal

I've put up a pull request to add @harrison9149! :tada:

@all-contributors add @jdcl32 for question

@abramenal

I've put up a pull request to add @jdcl32! :tada:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skjnldsv picture skjnldsv  Â·  5Comments

JaydenNavarro-at picture JaydenNavarro-at  Â·  5Comments

tkeswa picture tkeswa  Â·  5Comments

craig-dae picture craig-dae  Â·  5Comments

zach446 picture zach446  Â·  3Comments