Last active
June 29, 2021 12:25
-
-
Save andygock/9ab33cf9ed3ae0ce2145a09a3a4bafda to your computer and use it in GitHub Desktop.
Cypress.io testing multiple file drag and drop uploads
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
// drag and drop multiple files | |
Cypress.Commands.add("upload_files", (selector, fileUrlArray, type = "") => { | |
const files = []; | |
fileUrlArray.forEach((fileUrl) => { | |
cy.fixture(fileUrl, "base64") | |
.then(Cypress.Blob.base64StringToBlob) | |
.then((blob) => { | |
const nameSegments = fileUrl.split("/"); | |
const name = nameSegments[nameSegments.length - 1]; | |
files.push(new File([blob], name, { type })); | |
}); | |
}); | |
const event = { dataTransfer: { files: files } }; | |
return cy.get(selector).trigger("drop", event); | |
}); | |
// example test - files should be in the 'fixtures/' dir | |
describe("test drag and drop upload", () => { | |
it("test upload of 2 files", () => { | |
// drag and drop | |
cy.upload_files(".drop", ["myfile1.csv", "myfile2.csv"]); | |
// check for response | |
cy.get(".output").should("contain", "some text"); | |
}); | |
}); |
This solution gave me the error:
Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
Is this something you are also seeing?
Though it was working many years ago, it's very possible or likely it's not compatible with more recent versions of Cypress. I haven't checked or looked at it since then.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This solution gave me the error:
Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
Is this something you are also seeing?