我们可以选择使用空手道脚本过滤数据吗?
Can we have option to filter the data using Karate scripts?
我有以下 JSON 回复:
{
"name": "Cabinets, Enclosures and Racks",
"parentId": "",
"categoryId": "55040",
"count": "3291",
"categoryLevel": "TOP"
},
{
"name": "Cable Management and Accessories",
"parentId": "55040",
"categoryId": "55041",
"count": "573",
"categoryLevel": "MIDDLE"
},
{
"name": "Cable Management",
"parentId": "55041",
"categoryId": "55042",
"count": "467",
"categoryLevel": "BOTTOM"
},
我需要获取唯一的 TOP CategoryLevel 数据。有什么选择吗
是的,你为什么不更仔细地阅读文档:https://github.com/intuit/karate#jsonpath-filters
尝试将下面的内容粘贴到一个新的 Scenario
中,看看它是否有效:
* def response =
"""
[
{
"name":"Cabinets, Enclosures and Racks",
"parentId":"",
"categoryId":"55040",
"count":"3291",
"categoryLevel":"TOP"
},
{
"name":"Cable Management and Accessories",
"parentId":"55040",
"categoryId":"55041",
"count":"573",
"categoryLevel":"MIDDLE"
},
{
"name":"Cable Management",
"parentId":"55041",
"categoryId":"55042",
"count":"467",
"categoryLevel":"BOTTOM"
}
]
"""
* def top = $response[?(@.categoryLevel=='TOP')]
* match top[0] == { name: 'Cabinets, Enclosures and Racks', parentId: '', categoryId: '55040', count: '3291', categoryLevel: 'TOP' }
我有以下 JSON 回复:
{
"name": "Cabinets, Enclosures and Racks",
"parentId": "",
"categoryId": "55040",
"count": "3291",
"categoryLevel": "TOP"
},
{
"name": "Cable Management and Accessories",
"parentId": "55040",
"categoryId": "55041",
"count": "573",
"categoryLevel": "MIDDLE"
},
{
"name": "Cable Management",
"parentId": "55041",
"categoryId": "55042",
"count": "467",
"categoryLevel": "BOTTOM"
},
我需要获取唯一的 TOP CategoryLevel 数据。有什么选择吗
是的,你为什么不更仔细地阅读文档:https://github.com/intuit/karate#jsonpath-filters
尝试将下面的内容粘贴到一个新的 Scenario
中,看看它是否有效:
* def response =
"""
[
{
"name":"Cabinets, Enclosures and Racks",
"parentId":"",
"categoryId":"55040",
"count":"3291",
"categoryLevel":"TOP"
},
{
"name":"Cable Management and Accessories",
"parentId":"55040",
"categoryId":"55041",
"count":"573",
"categoryLevel":"MIDDLE"
},
{
"name":"Cable Management",
"parentId":"55041",
"categoryId":"55042",
"count":"467",
"categoryLevel":"BOTTOM"
}
]
"""
* def top = $response[?(@.categoryLevel=='TOP')]
* match top[0] == { name: 'Cabinets, Enclosures and Racks', parentId: '', categoryId: '55040', count: '3291', categoryLevel: 'TOP' }