I'm trying to save content of a file (.xml) into a variable and then using it on body's request. You can see in the code below that i'm using readFile to get content of the file "xml.xml" and then saving its value to a variable named "upload". In the body's request I'm using "upload" variable to fill an api's parameter named "file". See:
it.only('TESTES', () => {
cy.readFile('C:\\Users\\leonardo.pignato\\Desktop\\xml.xml').then(xml => {
upload = xml
cy.request({
url: "/api/",
method: "POST",
headers: { 'Content-Type': 'form-data', 'Authorization': `bearer ${token}` },
body: { file: upload }
}).its('status').should('be.equal', 200)
})
})
})
However, i get status 500 and this error: "error": "Cannot destructure property 'file' of 'httpRequest.files' as it is undefined."
Can someone tell me why this is happening?