Search code examples
apiautomationkarate

Karate | Can we set payload based on status code condition


We have a post request as below ''' { Parameter : "name" col : 1 } '''

if the status code is 200 then do nothing, if status code is 400, then set value : "test" in the above payload as below and send again.

''' { Parameter : "name" col : 1 value : "test" } '''


Solution

  • Yes.

    * if (responseStatus == 200) karate.abort()
    * request { second: 'time' }
    * method post
    

    If you want more ideas and also why you shouldn't do these kinds of "clever" tests, read this: https://stackoverflow.com/a/50350442/143475