首页 > 解决方案 > 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

标签: apikarate

解决方案


你的问题很难理解,我假设你想遍历一些给定的 JSON 数组并做一些动作。听起来您不是在“测试”和误用空手道!

要遍历 JSON 数组,请使用call. 参考文档:https ://github.com/intuit/karate#data-driven-features

要执行条件,请阅读文档的这一部分:https ://github.com/intuit/karate#conditional-logic

要执行“表单数据”,请阅读: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')

如何实施api1.featureapi2.feature是你的功课。请记住,在这两种情况下,您仍然可以访问该data变量。请阅读文档和示例!


推荐阅读