空手道-无法在空手道框架中使用forEach打印响应json的计数



JSON结构:

{"id":"occvv">
"选择":[
{
"id"e3A"br/>},
"愿望清单"真
};,
quot;项目":{
Wishlite:真
测试:假
},
"愿望清单":true
},
"项目":{
Wishlite:True
Test:false
},
"愿望清单":true
},
"项目":{
Wishlite:True
Test:false
},
"愿望清单":true
},
],
"创建":"2022-08-01T17:07:34.053238Z">
},
{
"id":"e455&",
&"Name":"new2&",
"Type":"test44&",
"Count":3,
"items":[
{
>items">},
"愿望清单"真
},
>项目":{
Wishlite:真
测试:假
},
"愿望清单":true
},
"项目":{
Wishlite:True
Test:false
},
"愿望清单":true
},
],
"创建":"2022-08-01T17:07:34.053238Z">
},

空手道代码

Given url baseUrl
And path  PathUrl
And request { body }
When method Post
Then status <responseCode>
Then print response
* def responseobj = response
* def listtype = karate.jsonPath(response,"$..choice..Type")
* print 'listtype',listtype
* def fun = function(arg) { return karate.jsonPath(arg,'$..choices..items.item') }
* karate.forEach(listtype, fun)

我正在尝试打印项目下所有列表类型的所有项目计数,方法是使用for each。

对于Karate.forEach passing listtype和Fun作为参数

只需执行以下操作:https://github.com/karatelabs/karate#karate-尺寸

* def size = karate.sizeOf(listtype)
* print size

最新更新