简体   繁体   中英

How to pass multiple parameters in post request in karate framework?

I have a JSON data file which has data like

{
  "Status": "Pending",
  "role": "manager",
  "client": "android",
  "user": "test@abc.com",
  "eTyres":
  {
    "Wheels": {
      "title": "Alloy Wheel",
      "value": "Yes"
    }
 }
}

Firstly, I want to read this data and when Wheels.value == Yes then I want to hit an API else hit another API Also, I would like to know how i can pass multiple parameters in post request or from the file.

Post request data is as follows:

title:Alloy_wheel__Info
part:acCooling
partTitle:AC Cooling
partValue:No

Above data i'm passing through "form-data" in postman.

Thanks in advance

Your question is hard to understand and I will assume that you want to loop over some given JSON array and do some actions. Sounds like you are not "testing" and mis-using Karate !

To loop over a JSON array, use call . Refer the docs: https://github.com/intuit/karate#data-driven-features

To do conditionals, read this part of the documentation: https://github.com/intuit/karate#conditional-logic

To do "form-data" read this: https://github.com/intuit/karate#form-field

* def data = { "Status": "Pending", "role": "manager", "client": "android", "user": "test@abc.com", "eTyres": { "Wheels": { "title": "Alloy Wheel", "value": "Yes" } } }
* eval data.eTyres.Wheels.value == 'Yes' ? karate.call('api1.feature') : karate.call('api2.feature')

How to implement api1.feature and api2.feature is a homework for you. Keep in mind that in both you will still have access to the data variable. And please read the docs and examples !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM