Sourabh Chapali
Sourabh Chapali

Reputation: 391

Karate - how to send body as form data

These are my fields in form-data

uploaded_by = [email protected]
status = true
file = Excel File to be uploaded

Here is the code I tried

    Given url baseUrl + uploadTemplate
    And multipart field uploaded_by = <user>
    And multipart field status = <status>
    And multipart field file = read('Template.xlsx')
    When method post
    Then status 200
    And match $.result == <result>

Examples: 
| user      | status | result  |
| '[email protected]' | true   | INITIAL |

Excel File is present in the same location where feature file is there , I am getting 500 error , But working well from POSTMAN

Upvotes: 2

Views: 5150

Answers (2)

Sourabh Chapali
Sourabh Chapali

Reputation: 391

It worked with following code

    Given url baseUrl + uploadTemplate
    And multipart field uploaded_by = <user>
    And multipart field status = <status>
    And multipart field file = { read: 'Template.xlsx', filename: 'Template.xlsx', contentType: 'multipart/form-data' }
    When method post
    Then status 200
    And match $.result == <result>

Upvotes: 0

Peter Thomas
Peter Thomas

Reputation: 58058

Use form field instead of multipart field: https://github.com/intuit/karate#form-field

Upvotes: 3

Related Questions