upload photos cypress
it('Uploads a CSV', () => {
cy.document().trigger('dragenter')
// you don't need to use cy.document() that is where my event listener is.
//you could use cy.get('element').trigger('dragenter')
cy.dropFile('test.csv')
})
cy.fixture('path/to/image.png').as('logo')
.get('input[type=file]').then(function(el) {
return Cypress.Blob.base64StringToBlob(this.logo, 'image/png')
.then(blob => {
el[0].files[0] = blob
el[0].dispatchEvent(new Event('change', {bubbles: true}))
})
})Cypress.Commands.add(
'dropFile', {
prevSubject: false
}, (fileName) => {
Cypress.log({
name: 'dropFile',
})
return cy
.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
// instantiate File from `application` window, not cypress window
return cy.window().then(win => {
const file = new win.File([blob], fileName)
const dataTransfer = new win.DataTransfer()
dataTransfer.items.add(file)
return cy.document().trigger('drop', {
dataTransfer,
})
})
})
}
)
Also in JavaScript:
- how to make a sprite javascript
- difference between type and method in ajax
- group all items with same name js
- class query css js all
- square brackets vs curly brackets javascript
- javascript add object to array
- geoJson
- editorconfig javascript example
- how to check value of checkbox in react
- angular one way property binding
- dart list files in directory
- string check javascript
- let scores = [80, 90, 70]; for (const score of scores) { console.log(score); }
- program to parenthesize an expression
- mv multiple directories
- iframe loader jquery
- vuejs filter array by dates
- js remove special characters
- javascript is not null
- javascript get parameter
- jquery remove class
- calculate log in javascript
- javascript regex only letters and spaces
- javascript push in specific index