Posting formData using cypress doesn't work
See original GitHub issueCurrent behavior:
Uploading file via POST
request of formData
doesn’t work.
Desired behavior:
Being able to post formData
using cypress POST
request.
Steps to reproduce:
The following code doesn’t work.
const formData = new FormData();
formData.set('file', new File(['data'], 'upload.txt'), 'upload.txt');
cy.request({
method: 'POST',
url: '/upload/end/point',
body: formData,
headers: {
'content-type': 'multipart/form-data',
},
});
Versions
cypress@2.1.0 ubuntu 16.04 LTS Chrome 66.0.3359
Issue Analytics
- State:
- Created 5 years ago
- Reactions:26
- Comments:32 (3 by maintainers)
Top Results From Across the Web
Uploading multipart/form-data from text file using Cypress
In Cypress sending form data using POST request is not working · Multipart formdata POST request just doesn't work in Cypress for me...
Read more >Cypress-upload-file-post-form - npm.io
It works for excel files. For both cases, the file to be uploaded / sent in the form will be placed in fixtures...
Read more >Send Data From The Application To The Cypress Test
We hit a slight problem. The application modifies the data before sending it. Of course, the test should know exactly what the expected...
Read more >request - Cypress Documentation
Cypress does not actually make an XHR request from the browser. We are actually making the HTTP request from Cypress (in Node). So,...
Read more >Issue - Garett Petersen
I came across a limitation with cypress while trying to upload an image using formData. Cypress cy.request() currently does not support formData submission....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
cc: @srinivasrk @ahmehri
I was able to get a formData submitted with a combination of a mix of answers I found.
I hope this helps you.
Add this to support/commands.js:
Then you’d be able to do the following in your tests:
Thanks @shwarcu this is pretty much everything you need. There are a couple of little things you need to make sure you do with this.
It would really be ideal for Cypress to add support for multipart/form-data requests using their cy.request() command, but this is a reasonable workaround for the moment. This is very picky on how everything is set up and executed, so it is likely to break with future Cypress updates.