如何验证邮递员中的动态值
How to validate dynamic values in postman
我想验证 JSON 响应正文中的一些必填字段。到目前为止,我使用的是静态测试方法,使用像这样的硬编码值
json_response = JSON.parse(responseBody);
x=json_response
pm.expect(x).to.equal("abc");
但我想重新运行我的测试脚本,所以我不想一次又一次地更改我的测试来验证这些值。谁能建议我如何验证我的回复正文。
{
"Name": "John",
"Contact number": 9826363660,
"Address": "xyz"
}
因为每次我都会在这些键中获得新值“姓名”“联系电话”“地址”
pm.response.json().hasOwnProperty("Name")
您可以使用 hasOwnProperty 来检查该字段是否存在
执行模式验证
var schema = {
type: "object",
properties: {
"NAME": {
"type":"string"
},
"ADDRESS": {
"type":"string"
},
"Contact Number": {
"type":"number"
}
}
};
pm.response.to.have.jsonschema(schema)
https://postman-quick-reference-guide.readthedocs.io/en/latest/schema-validation.html
我想验证 JSON 响应正文中的一些必填字段。到目前为止,我使用的是静态测试方法,使用像这样的硬编码值
json_response = JSON.parse(responseBody);
x=json_response
pm.expect(x).to.equal("abc");
但我想重新运行我的测试脚本,所以我不想一次又一次地更改我的测试来验证这些值。谁能建议我如何验证我的回复正文。
{
"Name": "John",
"Contact number": 9826363660,
"Address": "xyz"
}
因为每次我都会在这些键中获得新值“姓名”“联系电话”“地址”
pm.response.json().hasOwnProperty("Name")
您可以使用 hasOwnProperty 来检查该字段是否存在
执行模式验证
var schema = {
type: "object",
properties: {
"NAME": {
"type":"string"
},
"ADDRESS": {
"type":"string"
},
"Contact Number": {
"type":"number"
}
}
};
pm.response.to.have.jsonschema(schema)
https://postman-quick-reference-guide.readthedocs.io/en/latest/schema-validation.html