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
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 ?
Solution 1:
You have to import the package:
support/index.js
import 'cypress-file-upload';
Solution 2:
You need to Install cypress-file-upload dev dependency first:
npm i cypress-file-upload --save-dev
Then import it in cypress/support/index.js
import 'cypress-file-upload'