Cypress automatically includes a Buffer polyfill for the browser and exposes it as Cypress.Buffer.
Use Cypress.Buffer to manipulate binary data, similar to the nodejs Buffer class. Instances are returned by cy.readFile() and cy.fixture(), and it is used with .selectFile().
Cypress.Buffer.method()
Correct Usage
Cypress.Buffer.method()
Incorrect Usage
cy.Buffer.method() // Errors, cannot be chained off 'cy'
cy.readFile('images/logo.png', null).then((file) => {
expect(Cypress.Buffer.isBuffer(file)).to.be.true
// Do something with `file` Buffer here
})
.selectFile()
const files = []
for (var i = 1; i <= 10; i++) {
files.push(Cypress.Buffer.from(`Contents of file #${i}`))
}
// Attach 10 files, of the form "Contents of file #1", "Contents of file #2", etc.
cy.get('input[type=file]').selectFile(files)
| Version | Changes |
|---|---|
| 9.3.0 | Added Cypress.Buffer. |
© 2017 Cypress.io
Licensed under the MIT License.
https://docs.cypress.io/api/utilities/buffer