使用 Karate 匹配 SUM 或连接同一 JSON 数组的多个元素

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

拥有包含多组乐器(>100+)的 JSON 响应。如何将每个项目集

item_list
值与
item_number
item_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"
 },
 ...
 ...
 ...
 ...
 ...
]
arrays json testing automation karate
1个回答
0
投票

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

* 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
    
© www.soinside.com 2019 - 2024. All rights reserved.