Last active
November 8, 2018 19:20
-
-
Save valeriocs/e0062e48236c399de82a9f5bc66f18dd to your computer and use it in GitHub Desktop.
Cypress Upload custom command.
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
Cypress.Commands.add('upload_file', (fileName, selector) => { | |
return cy.get(selector).then(subject => { | |
return cy.fixture(fileName, 'base64') | |
.then(Cypress.Blob.base64StringToBlob) | |
.then(blob => { | |
const el = subject[0] | |
const testFile = new File([blob], fileName, { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) | |
const dataTransfer = new DataTransfer() | |
dataTransfer.items.add(testFile) | |
el.files = dataTransfer.files | |
return subject; | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
Selector can be css class/id or by input.