0

I was writing end to end test case for a site. In this site, user is supposed to upload python file. I want to test what happens if I rename png file with `.py extension and upload it. When I did manually, the website gave the error

ERROR: You have submitted a file factorial.py of type py but the contents are of image/png type

However, when I uploaded through cypress using cypress-file-upload plugin, it gave me following error:

ERROR: You have submitted a file factorial.py of type py but the contents are of application/octet-stream type

Why is this so? Am I missing something or am getting diffrent message because of the way the plugin uploads file in some peculiar manner? Can I imitate the manual file upload output through cypress (that is get exactly the same error of image/png type)?

Update

I also checked for the mp3 file. Manual upload was giving error:

ERROR: You have submitted a file factorial.py of type py but the contents are of audio/mpeg type

whereas cypress upload was giving same application/octet-stream type-error.

Also, my code to upload the file looks like this:

cy.get('input[name="docfile"]').attachFile(filePath)
cy.contains('input','Upload').click()

Explicitly adding a mimetype also doesn't work and still gives same error:

cy.get('input[name="docfile"]').attachFile({ filePath: _filePath, mimeType : _mimeType })
Rnj
  • 1,067
  • 1
  • 8
  • 23
  • Can you add the code to how you are uploading the file ? – ItsNotAndy Sep 21 '21 at 06:22
  • @ItsNotAndy Please find the code I have added at the bottom of the question. – Rnj Sep 21 '21 at 07:58
  • You might want to specify the file you are trying to upload. Im not sure exactly what it would look like, but will do some research and post a answer in a bit. Have a look at this for now. https://stackoverflow.com/questions/57925670/how-to-upload-an-pdf-file-with-cypress-io/69104009#69104009 – ItsNotAndy Sep 21 '21 at 08:09
  • I downloaded random image online and changed its file type to `*.py` and tried its upload. Also it didn't work by explicitly specifying mimetype as `cy.get('input[name="docfile"]').attachFile({ filePath: _filePath, mimeType : _mimeType })`. – Rnj Sep 21 '21 at 08:44

0 Answers0