abramenal/cypress-file-upload

[Bug] attachFile does not work with xml encoded files

eduardovostrofischer opened this issue · 5 comments

Currently trying to upload xml file but i can't make it work.

Code:

cy.contains('invoice').attachFile({filePath:'invoice.xml', encoding: 'xml'});

Current behavior:

"file encoding" is not valid.
Please look into docs to find supported "encoding" values

Desired behavior:

Sucessfully upload file.

@eduardovostrofischer Can you try utf-8?

cy.contains('invoice').attachFile({filePath: 'invoice.xml', encoding: 'utf-8'});

I am having same issue

Working for me . Here is the code.

cy.fixture("SmallXML_changedToV1_2.xml").then((fileContent) => {
cy.visit(/survey/22111100927)
.login()
.get('input[type="file"]')
.attachFile({ fileContent: ${fileContent} });
});

Encoding and file extension are conceptually different things here. I think it should work either by just omitting the encoding, or setting it to utf-8.

Added reference to this issue

It might be interesting for people still running into issues with this that the default mimeType for XML files in attachFile will be 'application/xml' and not 'text/xml'. We had an issue with this because our API only accepted 'text/xml' and we assumed that the type as okay. Once we configured the mimeType to 'text/xml' it all worked fine!