Software Development and QA Tips

Dev and QA Tips How Do I Upload a File in Cypress.io?

How Do I Upload a File in Cypress.io?

Nearshore QA, Performance Metrics | By Vakul Gotra | October 12, 2020

The JavaScript End to End Testing Framework is a highly popular framework nowadays. However, there are a few browser events that are not supported by cypress. File uploading is one such event.

To upload a file in cypress, you need to install a dependency to upload the file. Follow these steps:

  1. Install the dependency

    npm install cypress-file-upload

  2. Add import

    ‘cypress-file-upload’; to cypress/support/commands.js file

  3. Go to spec file where you are creating your test code:
    declare a constant having path of your file and use attachFile command.

Example:

const urFilePath = 'abc.png';

cy.get('#elementID').attachFile(urFilePath);

Disclaimer

This publication is for informational purposes only and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.