使用match每个包含的json数组项声明 [英] Using match each contains for json array items assertion
问题描述
我想在技能数组中添加一个断言,该数组在响应数组下的每个项目中都包含培训".如何使用匹配每种格式* match each response contains { password: 'abc123' }
的方法(不使用JsonPath表达式)来做到这一点.我期望我的测试在以下示例中失败,因为第四对象中缺少技能数组.
I would like to add an assertion on skills array containing 'training' in each of the items under response array. how can I do this using match each format * match each response contains { password: 'abc123' }
(without using JsonPath expression). I'm expecting my test to be failed for below example since skills array is missing in fourth object.
Scenario: Test scenario
* def response =
"""
[
{
id: 1,
name: "John",
password: "abc123",
skills :[ "training", "management"
]
},
{
id: 2,
name: "David",
password: "abc123",
skills :[ "training", "management"
]
},
{
id: 3,
name: "David",
password: "abc123",
skills :[ "training", "coding"
]
},
{
id: 4,
name: "David",
password: "abc123"
}
]
"""
推荐答案
在这里:
* def expectedSkills = ['training']
* match each response contains { skills: '#(^expectedSkills)' }
您知道,您应该真正阅读该文档.这将为您节省大量时间:) https://github.com/intuit/karate#模式验证
You know, you should really read the documentation. It will save you a LOT of time :) https://github.com/intuit/karate#schema-validation
这篇关于使用match每个包含的json数组项声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!