1

cy.fixture('images.png').then(fileContent => {
            cy.xpath(this.proof_of_address)
                .attachFile({ fileContent, fileName: 'images.png', mimeType: 'image/png' });
        });

I uploaded the image file with this cypress code and the cypress didn't give me any error, also successfully upload an image file. After execution, When I go to preview the image the error is showing images.

But when I click to preview the image it shows me an error.

enter image description here

I don't understand where my mistake is or if am I missing something

1 Answers1

1

Before uploading the image file, it should be converted to Blob first.

cy.fixture('images.png')
  .then(Cypress.Blob.base64StringToBlob)
  .then(fileContent => {
    cy.xpath(this.proof_of_address)
      .attachFile({
        fileContent,
        fileName: 'images.png',
        mimeType: 'image/png'
      });
  });

Reference: https://docs.cypress.io/api/utilities/blob

Ry-ry
  • 210
  • 1
  • 4
  • 15