我的响应可能包含以下递归对象:
"categoriesArray": [
{
"id": "category1",
"href": "/categories/categoryId/category1",
"name": "category name 1",
"categoriesArray": [
{
"id": "category2",
"href": "/categories/categoryId/category2",
"name": "category name 2",
}
]
}
]
我想按以下顺序匹配所有ID:
那么RestAssured中有诸如appendRoot(“ response [0] .categoriesArray [0] .categoriesArray”)之类的快捷方式,可以在不重复路径的情况下更深入吗?
答案 0 :(得分:1)
是的,使用JsonPath,您可以选择非常明智的选择。我认为这对您有用:
* def response =
"""
{
"categoriesArray": [
{
"id": "category1",
"href": "/categories/categoryId/category1",
"name": "category name 1",
"categoriesArray": [
{
"id": "category2",
"href": "/categories/categoryId/category2",
"name": "category name 2"
}
]
}
]
}
"""
* match response..id contains ['category1', 'category2']
* def cat1 = response.categoriesArray[0]
* match cat1..id contains 'category2'
* match response.categoriesArray[?(@.id=='category1')].categoriesArray..id contains 'category2'
编辑:添加了更多选项以回应评论