UNPKG

cypress-upload-file-post-form

Version:

Solution for two Cypress testing use-cases I came across with: perform a direct http FORM request to the server containing a file and other parameters and upload a file into a form before submission

19 lines (14 loc) 768 B
// Upload an excel file, fill in other inputs and submit the form describe('Testing the excel form', function () { it ('Uploading the right file imports data from the excel successfully', function() { const testUrl = 'http://localhost:3000/excel_form'; const fileName = 'your_file_name.xlsx'; const fileType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; const fileInput = 'input[type=file]'; cy.visit(testUrl); cy.upload_file(fileName, fileType, fileInput); cy.get('#other_form_input2').type('input_content2'); cy.get('button').contains('Submit').click(); cy.get('.result-dialog').should('contain', 'X elements from the excel where successfully imported'); }) })