Sanchit
Sanchit

Reputation: 63

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": "[email protected]",
  "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

Upvotes: 2

Views: 4461

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58128

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": "[email protected]", "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 !

Upvotes: 1

Related Questions