Simple custom Cypress command to ease file upload testing.
This module is distributed via npm which is bundled with uglify-es and should be installed as one of your project's devDependencies
:
npm install --save-dev cypress-file-upload
cypress-file-upload
extends Cypress' cy
command.
Add this line to your project's cypress/support/commands.js
:
import 'cypress-file-upload';
Here is a simple example:
cy.fixture('data.json', 'base64').then(fileContent => {
cy.get('[data-cy="dropzone"]').upload(
{ fileContent, fileName: 'data.png', mimeType: 'application/json' },
{ subjectType: 'drag-n-drop' },
);
});
Please see full version in example.
Exposed command in a nutshell:
cySubject.upload(fileOrArray, processingOpts);
fileOrArray
is an object (or an array of those) that represents file information and contains following properties:
- {String}
fileContent
– raw file content - {String}
fileName
– file name with extension - {String}
mimeType
– file mime type
processingOpts
contains following properties:
- {String}
subjectType
– target (aka subject) element kind:'drag-n-drop'
component or plain HTML'input'
element. Defaults to'input'
.
Thanks goes to these wonderful people (emoji key):
James Hollowell 💻 |
Oliver O'Donnell 💻 |
Peter Colapietro 📖 |
km333 🐛 |
Kevin Mui 💻 |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!