Software Development and QA Tips By QASource Experts

How Do I Upload a File in Cypress.io?

Written by Timothy Joseph | Oct 12, 2020 4:00:00 PM

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);