abramenal / cypress-file-upload

File upload testing made easy
https://npm.im/cypress-file-upload
MIT License
498 stars 89 forks source link

[Bug] Cypress 5.0 doesn't like FixtureData object #222

Closed josephzidell closed 4 years ago

josephzidell commented 4 years ago

Current behavior:

binaryStringToBlob() no longer returns a Promise. Update the use of binaryStringToBlob() to expect a returned Blob

Desired behavior:

The file object uploads

Steps to reproduce: (app code and test code)

cy.get('[type=file]').attachFile({fileContent: blob, filePath: 'file.xml', encoding: 'utf-8'});

Versions

Cypress: 5.0 Operating system: Mac Browser: Firefox

saschwarz commented 4 years ago

I'm seeing this too with the 4.1.0 version of this plugin.

Looking at the code in the traceback it looks like the fileContent is wrapped with a Promise and that triggers the Cypress deprecation: https://github.com/abramenal/cypress-file-upload/blob/b773da5be776a309f2b8b261911e9bead118869e/lib/file/getFileContent.js#L4

I'm not sure what the solution should be. In my code I ended up doing:

      cy.fixture('file.xls', 'binary')
        .then((binaryContent) => {
          const fileContent = Cypress.Blob.binaryStringToBlob(binaryContent)
          delete fileContent.then;   // <== THIS
          cy.get('input[data-testid=file-input]').attachFile({
            fileContent,
            fileName: 'file.xls',
            mimeType:
              'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            encoding: 'utf8',
          })
        })
TheMY3 commented 4 years ago

Same problem with Cypress 5.0

danielcaballero commented 4 years ago

I opened PR https://github.com/abramenal/cypress-file-upload/pull/225

I'm seeing this too with the 4.1.0 version of this plugin.

Looking at the code in the traceback it looks like the fileContent is wrapped with a Promise and that triggers the Cypress deprecation: https://github.com/abramenal/cypress-file-upload/blob/b773da5be776a309f2b8b261911e9bead118869e/lib/file/getFileContent.js#L4

I'm not sure what the solution should be. In my code I ended up doing:

      cy.fixture('file.xls', 'binary')
        .then((binaryContent) => {
          const fileContent = Cypress.Blob.binaryStringToBlob(binaryContent)
          delete fileContent.then;   // <== THIS
          cy.get('input[data-testid=file-input]').attachFile({
            fileContent,
            fileName: 'file.xls',
            mimeType:
              'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            encoding: 'utf8',
          })
        })