遍历动态数组并在下一个请求中重复使用值

问题描述 投票:1回答:1

我想执行以下操作:

  1. 向服务器发送请求,并检索宠物店中可用动物的详细信息。

post / getAnimalStatus响应:

    "animals": [
        {
            "animalId": "567839",
            "gender": "Female",
            "age": 2,
            "isEligibleAsPet": true,
            "animalStatus": "AVAILABLE"
        },
        {
            "animalId": "648562",
            "gender": "Male",
            "age": 3,
            "isEligibleAsPet": true,
            "animalStatus": "AVAILABLE"
        },
        {
            "animalId": "965895",
            "gender": "Female",
            "age": 5,
            "isEligibleAsPet": false,
            "animalStatus": "UNAVAILABLE"
        }
    ]
}

然后我想:

  1. 搜索响应中所有为UNAVAILABLE的动物并将数组值存储在变量中。
  2. 向服务器发送请求,以将全部不可用动物的状态更新为“可用”
  3. 此请求的格式如下,其中我们在下面的animal对象中使用来自上面响应的数组值。:

put / updateAnimals

    "animal": {
        "animalId": "965895",
        "gender": "Female",
        "age": 5,
        "isEligibleAsPet": false,
        "animalStatus": "UNAVAILABLE"
    },
    "updateStatus": "AVAILABLE"
}
karate jsonpath
1个回答
0
投票
  1. 使用JsonPath(或karate.filter())进行操作:https://github.com/intuit/karate#jsonpath-filters

  2. 使用第二个特征文件和call进行迭代:https://github.com/intuit/karate#data-driven-features

请提出更具体的问题,以获得更具体的答案。

© www.soinside.com 2019 - 2024. All rights reserved.