Skip to content

Instantly share code, notes, and snippets.

@tlylt
Created May 21, 2021 05:45
Show Gist options
  • Save tlylt/8c55589cec793bb4104f990ec5328f07 to your computer and use it in GitHub Desktop.
Save tlylt/8c55589cec793bb4104f990ec5328f07 to your computer and use it in GitHub Desktop.
Cypress upload excel file
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