showing results for - "upload photos cypress"
Liana
02 May 2018
1cy.fixture('path/to/image.png').as('logo')
2  .get('input[type=file]').then(function(el) {
3    return Cypress.Blob.base64StringToBlob(this.logo, 'image/png')
4      .then(blob => {
5        el[0].files[0] = blob
6        el[0].dispatchEvent(new Event('change', {bubbles: true}))
7      })
8  })
Luciano
21 Aug 2016
1it('Uploads a CSV', () => {
2    cy.document().trigger('dragenter')
3    // you don't need to use cy.document() that is where my event listener is. 
4   //you could use cy.get('element').trigger('dragenter')
5    cy.dropFile('test.csv')
6})
7
Antonio
23 Nov 2016
1Cypress.Commands.add(
2    'dropFile', {
3        prevSubject: false
4    }, (fileName) => {
5        Cypress.log({
6            name: 'dropFile',
7        })
8        return cy
9            .fixture(fileName, 'base64')
10            .then(Cypress.Blob.base64StringToBlob)
11            .then(blob => {
12                // instantiate File from `application` window, not cypress window
13                return cy.window().then(win => {
14                    const file = new win.File([blob], fileName)
15                    const dataTransfer = new win.DataTransfer()
16                    dataTransfer.items.add(file)
17
18                    return cy.document().trigger('drop', {
19                        dataTransfer,
20                    })
21                })
22            })
23    }
24)
25