1

I have a below use case in API automation framework which was built using karate I store my request payload as a JSON file under the test payload folder under classpath and I tried to update values for a couple of keys (using SET keyword, print shows the updated request JSON) before posting the request using and then I have called the same file as multipart form data when I execute it, set keyword updates the requested keys in the request payload but while posting it uses the file with old values can someone guide me on how to dynamically update the request payload and use the same file as multipart form data in post request using karate

    Background:
    * url baseurl 
    * header accept = '*/*'
    @test 
    Scenario Outline: to test with different data
    given path 'v1/api/'
    And def RequestBody = read('classpath:testpayload/<Testtype>.json>')
    And set RequestBody.orderID = '280120221234'
    And set RequestBody.subdate = '<submitteddate>'
    And print 'reqpl:', RequestBody
    And multipart field testdata ={read:'classpath:testpayload/<Testtype>.'json',filename:<Testtype>.'json', contentType: 'multipart/form-data'}
    And method post 
    Then status 200 

    Examples: 
    |Testtype |submitteddate|
    |test1data|28012022     |
``````````````````````````````
hamsa raj
  • 39
  • 1
  • 5
  • please assume that this is not supported by karate, unless you write some custom java code. also please read the linked answer, you typically NEVER need to write to any file to do assertions (or build new payloads). please don't do it - it wastes time and is a very bad practice in my opinion – Peter Thomas Jan 28 '22 at 18:50
  • I think you misunderstood the requirements, my objective is not to write the request payload to any external file, I'm trying to take a request json and update the same payload and use it as a input to multipart form data for post request My whole idea to avoid referring to multiple request json files and instead use one payload as template and achieve other test coverage through examples – hamsa raj Jan 29 '22 at 19:29
  • please see this answer, instead of `read` use `value` and an embedded expression: https://stackoverflow.com/a/68844563/143475 - also see: https://stackoverflow.com/a/56370149/143475 – Peter Thomas Jan 30 '22 at 03:55
  • 1
    That's really brilliant, it worked thanks for your quick support .... Karate is awesome – hamsa raj Jan 31 '22 at 11:36
  • great, glad it worked ! and sorry I misunderstood. I read questions in a big hurry, so next time - try to keep the question simple – Peter Thomas Jan 31 '22 at 11:50

0 Answers0