使用Karate匹配相同JSON数组的多个元素的SUM或串联

zlhcx6iw  于 2023-08-08  发布在  其他
关注(0)|答案(1)|浏览(107)

有一个JSON响应,在多个集合中有这么多乐器(>100+)。如何最好地匹配每个项目集item_list值与item_numberitem_info的精确总和或串联。
验证在以下求和或级联时失败:
* match each response[*].item_list = $response[*].item_number + "--" + $response[*].item_info

[{
   "item_number":01,
   "item_info": "Piano",
   "item_list": "01--Piano"
 },
 {
   "item_number":02,
   "item_info": "Mrudanga",
   "item_list": "02--Mrudanga"
 },
 {
   "item_number":03,
   "item_info": "Guitar",
   "item_list": "03--Guitar"
 },
 {
   "item_number":04,
   "item_info": "Flute",
   "item_list": "04--Flute"
 },
 ...
 ...
 ...
 ...
 ...
]

字符串

6tqwzwtp

6tqwzwtp1#

如果数值正确,这将起作用:

* match each response contains { item_list: "#(_$.item_number + '--' + _$.item_info)" }

字符串
您可能需要做一些预处理:

* def data = response.map(x => String(x.item_number).padStart(2, '0') + '--' + x.item_info)
* match response[*].item_list == data

相关问题