Created
May 21, 2021 05:45
-
-
Save tlylt/8c55589cec793bb4104f990ec5328f07 to your computer and use it in GitHub Desktop.
Cypress upload excel file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('uploads a file', () => { | |
cy.fixture('sample.xlsx','binary').as('sample') | |
cy.get('input[type="file"]').then(function (el) { | |
const blob = Cypress.Blob.binaryStringToBlob(this.sample) | |
const file = new File([blob], 'sample.xlsx', { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) | |
const list = new DataTransfer() | |
list.items.add(file) | |
const myFileList = list.files | |
el[0].files = myFileList | |
el[0].dispatchEvent(new Event('change', { bubbles: true })) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment