Created
March 17, 2020 03:23
-
-
Save bpceee/be13c298ecb6b3147a0189b1ad0c4600 to your computer and use it in GitHub Desktop.
cypress file upload
This file contains 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
const uploadFile = (fileName, fileType = '', selector) => { | |
cy.get(selector).then(subject => { | |
cy.fixture(fileName, 'base64') | |
.then(Cypress.Blob.base64StringToBlob) | |
.then(blob => { | |
const el = subject[0] | |
const testFile = new File([blob], fileName, { type: fileType }) | |
const dataTransfer = new DataTransfer() | |
dataTransfer.items.add(testFile) | |
el.files = dataTransfer.files | |
console.log(el.files) | |
}) | |
}) | |
// from https://bparkerproductions.com/testing-file-uploads-with-cypress-io/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment