Search code examples
karateform-data

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


Solution

  • 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>