Api 如何在jmeter中验证响应数据模式(仅列值)?
我需要在jmeter中验证API模式。 我的API响应数据是Api 如何在jmeter中验证响应数据模式(仅列值)?,api,jmeter,assertion,Api,Jmeter,Assertion,我需要在jmeter中验证API模式。 我的API响应数据是 [{ "snid": "1", "subject": "Automation", "state": null, "country": null, "contact_name": "John", "email": "John@gmail.com", "phone": "402-221-9999" }, { "snid": "2", "subject": "Testi
[{
"snid": "1",
"subject": "Automation",
"state": null,
"country": null,
"contact_name": "John",
"email": "John@gmail.com",
"phone": "402-221-9999"
}, {
"snid": "2",
"subject": "Testing",
"state": null,
"country": null,
"contact_name": "Smith",
"email": "jmstauch@leoadaly.com",
"phone": "402-111-2222"
}]
因此,我想验证它是否包含响应消息
{
"snid": "",
"subject": "",
"state": ,
"country": ,
"contact_name": "",
"email": "",
"phone": ""
}
我只需要验证列名称和字段的顺序。
我使用了response断言
contains,但它不验证顺序,也JSON路径断言
验证对象值,而不是参数(或验证完整消息),但在我的情况下,我需要验证确切的模式
请提供帮助我建议使用和,即,目前没有相关的捆绑测试元素和/或插件来涵盖此功能。一定要把.jar放进去
有关在JMeter中使用Groovy脚本的更多信息,请参阅本文 您可以使用
map.keySet()
,它将为您提供映射中的所有键
[ "snid",
"subject",
"state",
"country",
"contact_name",
"email",
"phone"
]
我找到了一份适合你的工作 首先将对象解析为json slurper
def slurper = new groovy.json.JsonSlurper();
def response = slurper.parseText(prev.getResponseDataAsString());
def testdata = response[0].keySet() as List;
这将把测试数据保存为
[“snid”、“主题”、“州”、“国家”、“联系人姓名”、“电子邮件”、“电话”]