Cypress.Buffer
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()
.
Syntax
Cypress.Buffer.method()
Usage
Correct Usage
Cypress.Buffer.method()
Incorrect Usage
cy.Buffer.method() // Errors, cannot be chained off 'cy'
Examples
Loading binary data read from disk
cy.readFile('images/logo.png', null).then((file) => {
expect(Cypress.Buffer.isBuffer(file)).to.be.true
// Do something with `file` Buffer here
})
.selectFile()
Using dynamic file contents with 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)
History
Version | Changes |
---|---|
9.3.0 | Added Cypress.Buffer . |