mardi 25 septembre 2018

Cypress, problem with adding an image to tests

[Automatic tests, tool: Cypress]

Hi all,

I would like to add an image, but I got some errors.

I used code:

cy.fixture("logo.jpg").as("logo")
cy.get('input[type=file]').eq(0).then(subject => {       
      return Cypress.Blob.base64StringToBlob(this.logo, "image/jpeg").then((blob) => {
            const el = subject[0]
            const testFile = new File([blob], 'logo.jpg', { type: 'image/jpeg' })
            const dataTransfer = new DataTransfer()
            dataTransfer.items.add(testFile)
            el.files = dataTransfer.files
       })
})

Then I received an error:

TypeError: Cannot read property 'logo' of undefined

When I gave cy.fixture("logo.jpg") into a const variable, then I received an error:

InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

I have the same situation, the same problems even when I want to use the code from the documentation:

cy.fixture("logo.jpg").as("logo")
cy.get("input[type=file]").eq(0).then(($input) => {
    // convert the logo base64 string to a blob
    return Cypress.Blob.base64StringToBlob(this.logo, "image/jpeg").then((blob) => {
        // pass the blob to the fileupload jQuery plugin
        // used in your application's code
        // which initiates a programmatic upload
        $input.fileupload("add", { files: blob })
    })
})

Did anyone have similar problems or maybe anyone has any ideas?

Aucun commentaire:

Enregistrer un commentaire