尝试以下代码来验证两个数组中是否都存在定义的架构,不起作用。
* def schema = {"category": "reference","author": "Nigel Rees","title": "Sayings of the Century", "price": 8.95}
* def bookdetails= $api.store.book[*]
* match bookdetails contains schema
Json:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
}],
[{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
}]}}
答案 0 :(得分:1)
由于您是堆栈溢出的新手,请阅读以下内容以获取最佳帮助:
https://stackoverflow.com/help/how-to-ask https://stackoverflow.com/help/someone-answers
问题中的json格式不正确,并且不是有效的json。以下示例代码有效:
Feature: Match
Scenario: Match
* def api =
"""
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
}
]
}
}
"""
* def schema = {"category": "reference","author": "Nigel Rees","title": "Sayings of the Century", "price": 8.95}
* def bookdetails = $api.store.book[*]
* match bookdetails contains schema