abramenal / cypress-file-upload

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

[Feature] Upload files out of /cypress/fixtures folder #232

Closed MCFreddie777 closed 3 years ago

MCFreddie777 commented 4 years ago

Current behavior:

cy.get(this.fileInput).attachFile('/cypress/auth/mysql/mysql.json');
cy.get(this.fileInput).attachFile({fileName: 'mysql.json', filePath: '/cypress/auth/mysql/mysql.json'});

both result in

A fixture file could not be found at any of the following paths:
> cypress/fixtures/cypress/auth/mysql/mysql.json

Desired behavior:

Seems like the package is using cy.fixture instead of cy.readFile which appends cypress/fixtures by default, therefore its impossible to upload file elsewhere than this folder.

Versions

Cypress: 4.12.1 Chrome: 85 OS: macOS 10.15 Catalina

abhidp commented 3 years ago

@MCFreddie777 Until this bug/feature is fixed, you can use the the readFile option as a workaround

const filePath = 'cypress/downloads/example.csv'

cy.readFile(this.fileInput, 'binary')
  .then(Cypress.Blob.binaryStringToBlob)
  .then((fileContent) => {
    cy.get(this.fileInput).attachFile({
      filePath,
      fileContent
    })
  })