- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to upload a file in Cypress?
We can upload a file in Cypress. To perform the file upload task in Cypress, we have to first install a plugin with the command −
npm ins tall –dev cypress-file-upload
Once the installation is done, we have to add the statement import 'cypress-fileupload' in the command.js file which resides inside the support folder within our Cypress project. Also, we shall add the file that we want to upload within the fixtures folder(Picture.png file).
To upload a file, we have to use the Cypress command, attachFile, and pass the path of the file to be uploaded as a parameter to it.
Example
Implementation
describe('Tutorialspoint Test', function () { // test case it('Test Case6', function (){ //file to be uploaded path in project folder const p = 'Picture.png' // launch URL cy.visit("https://the-internet.herokuapp.com/upload") //upload file with attachFile cy.get('#file-upload').attachFile(p) //click on upload cy.get('#file-submit').click() //verify uploaded file cy.get('#uploaded-files').contains('Picture') }); });
Execution Results
The execution logs show that the file Picture.png got uploaded and the file name got reflected on the page.
- Related Articles
- How to upload a file using JSP?
- How to create a file upload button with HTML?
- How to upload file with selenium (Python)?
- How to upload a file in Selenium with no text box?
- How can you upload a file using JSP?
- How to upload file without form using JavaScript?
- File Upload Example in Python
- How to handle windows file upload using Selenium WebDriver?
- How to upload a big CSV file in SAP Hybrid mobile app quickly?
- Using GUI upload to attach a file to email in SAP
- How do we do a file upload using Python CGI Programming?
- Upload file with php to another php server
- How do we upload external file on a website using HTML forms?
- CSS Styling of File Upload Button with ::file-selector-button Selector
- How to create a Mochawesome report in Cypress?

Advertisements