Last active
October 7, 2018 15:08
-
-
Save neymarsabin/7428fa21905d0dcd5b5ac11d8a9a72f8 to your computer and use it in GitHub Desktop.
Cypress Upload a File
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
7428fa2... 10/07/18 20:50 public Cypress Upload a File | |
+ 61877cc... 09/08/17 11:35 public API JSON authentication with Devise | |
3740394... 07/30/17 09:57 public These are some of my project references in socialnetwork application in ruby on rails. | |
86c208e... 07/25/17 19:53 public |
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
Cypress.Commands.add('upload_file', (selector, fileUrl, type = '') => { | |
return cy.fixture(fileUrl, 'base64') | |
.then(Cypress.Blob.base64StringToBlob) | |
.then(blob => { | |
const nameSegments = fileUrl.split('/') | |
const name = nameSegments[nameSegments.length - 1] | |
const testFile = new File([blob], name, { type }) | |
const event = { dataTransfer: { files: [testFile] } } | |
return cy.get(selector).trigger('drop', event) | |
}) | |
}); | |
// Usage | |
cy.upload_file('.dropzone, trade.xlsx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment