Cypress: Not able to upload jpg image in cypress

Created on 23 May 2019  路  2Comments  路  Source: cypress-io/cypress

I am trying to upload a jpg file using cypress and this is that i have tried so far

I have install plugin cypress-file-upload
I have import this import cypress-file-upload in ./cypress/commands.js

const fileName = 'img112.jpg';
        cy.fixture(fileName, 'base64').then(fileContent => {
             cy.get('input[type="file"]').upload(
                { fileContent, fileName, mimeType: 'image/jpg' },
                { subjectType: 'input' },
                );
        });

Here is my HTML Code:
12345

After that I am getting error like - TypeError: cy.get(...).upload is not a function at my end

Node Version: v10.15.3
npm Version : 6.1.0
Cypress Version : 3.3.0

Most helpful comment

I have the same problem, even after installing the extension and adding import 'cypress-file-upload'; to my commands.js file. Was anybody able to fix this?

Fixed: seems like the function is now called attachFile instead of upload

All 2 comments

The .upload command is not part of Cypress, you have to install a plugin to use it: https://github.com/abramenal/cypress-file-upload

Check out the README there for usage information.

I have the same problem, even after installing the extension and adding import 'cypress-file-upload'; to my commands.js file. Was anybody able to fix this?

Fixed: seems like the function is now called attachFile instead of upload

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EirikBirkeland picture EirikBirkeland  路  3Comments

SecondFlight picture SecondFlight  路  3Comments

brian-mann picture brian-mann  路  3Comments

carloscheddar picture carloscheddar  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments