In cypress-file-upload v3 I could do something like the following, to bypass a known Cypress.fixture issue documented here: https://github.com/cypress-io/cypress/issues/3138
cy.fixture(fileName)
.then(fileContent => {
cy.get(<selector>).upload({
JSON.stringify(fileContent),
fileName: fileName,
mimeType: 'application/json',
encoding: 'utf8'
})
})
Now in v4, since the Cypress.fixture line is built into the behaviour of the attachFile function (https://github.com/cypress-io/cypress/issues/3138), I am seeing that the uploaded file is formatted as [Object object].
Instead of [Object object], I'd expect to see the actual JSON object like I used to be able to by running JSON.stringify on the file returned by Cypress.fixture.
Dropzone component which reads the file:cy.get(<selector>).attachFile(
{ filePath: <JSON file>, mimeType: 'application/json', encoding: 'utf-8' },
{ subjectType: 'drag-n-drop', force: true }
)
[Object object][email protected]
Mac OS X 10.7.4
Chrome 80
Hi @sanduteo95
Thanks for submitting the issue!
Good catch, didn't know about that workaround.
Will let you know once this is fixed. If I'll get more issue with other fixture types I'll consider keeping original complex API as well.
Hi @abramenal, do you have an ETA for this fix?
I have a similar flow to this one but using wsdl and spss files, I have submitted a PR that allow us to keep the workaround: https://github.com/abramenal/cypress-file-upload/pull/184
A change of @jdcl32 is released in v4.0.5 so please take a look and let us know if something isn't working still.
@abramenal I just tried with 4.0.6 and I still get [Object object] unfortunately
I have a similar problem with json files in v4.0.6 but thanks to the new option fileContent, it's allowed me to build a workaround. Basically, I fix the Cypress behavior by manually serializing the json object back into blob.
Cypress.Commands.add(
'dropJsonFile',
{
prevSubject: true,
},
(subject, filePath: string) => {
cy.fixture(filePath, 'binary').then((fileContent) => {
cy.wrap(subject).attachFile(
{
fileContent: new Blob([JSON.stringify(fileContent, null, 2)], {
type: 'application/json',
}),
filePath: filePath,
encoding: 'utf-8',
},
{ subjectType: 'drag-n-drop' }
);
});
}
);
Just released the fix
Most helpful comment
Hi @sanduteo95
Thanks for submitting the issue!
Good catch, didn't know about that workaround.
Will let you know once this is fixed. If I'll get more issue with other fixture types I'll consider keeping original complex API as well.