Search code examples
testingcucumberkarate

Karate v1.4.0 - Multipart not working when executed from jar file


I have a feature where I send a request with a multipart file using this line:

And multipart file csvFile = {read: '#(filePath)', contentType:'multipart/form-data'}

This is working perfectly with the Karate v1.4.0 from my local eclipse but when I compile as jar file and execute with "java -jar" command, the test is not working, it's sending the request with the file but the server is saying the multi-part is not right.

When I try the same with Karate v1.3.1 everything works perfectly, it seems something related with the version 1.4.0.

Has someone the same problem with multipart with the latest version?

INFO:

Log when it works v1.4.0 from eclipse:

enter image description here

Log when it doesn't work from jar file:

  • See strange line 10 where the filename is not set by karate
  • See strange line 25 where karate set content-type: applicattion/jon??

enter image description here


Solution

  • I don't know the real reason but I solved it, adding to the multipart command a 'filename' attribute:

    And multipart file csvFile = {read: '#(filePath)', contentType:'multipart/form-data', filename: '#(fileName)'}
    

    It's strange because following the documentation (https://github.com/karatelabs/karate#multipart-file) the "filename" attribute is optional. Maybe it's a workaround to solve the problem in the v.1.4.0

    I don't know if this bug is going to be resolved on karate next version or otherwise the karate doc must be changed.