Skip to content
Advertisement

cypress-file-upload attachFile is not a function

I want to test my file uploading function using Cypress-file-upload but I hurt myself against .attachFile is not a function

enter image description here

I tried two solutions and I still can’t make it works :

// 1st one, "find file input" works

  it('find file input', () => {
    cy.get('input[type="file"')
  })
  
  const fileName = 'french_tweets_split.csv';
  it('Testing csv uploading', () => {
    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' })
    })
  })
// 2nd one, "find file input" works
  it('find file input', () => {
    cy.get('input[type="file"')
  })
  
  it('Testing csv uploading', () => {
    cy.fixture('french_tweets_split.csv').then(fileContent => {
        cy.get('input[type="file"]').attachFile({
            fileContent: fileContent.toString(),
            fileName: 'french_tweets_split.csv',
            mimeType: 'text/csv'
        })
    })
  })

What am I doing wrong ?

Advertisement

Answer

You have to import the package:

support/index.js

import 'cypress-file-upload';
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement