[英]How to validate dynamic values in postman
我想驗證我的 JSON 響應正文中的一些必填字段。 到目前為止,我正在使用 static 通過使用類似這樣的硬編碼值進行測試
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.