我希望向环境变量中添加一个有效负载模式,以便根据该模式验证响应有效负载。
我的环境变量定义如下:
responseSchema:
{ "properties":
"firstname":
{"type":"string" },
"lastname":
{"type":"string"},
"phonenumber":
{"type":"integer","format":"int64"}
},
"required":["firstname", "lastname", "phonenumber"]}
但是,我无法在我的邮递员测试代码中访问这个环境变量。我试着通过以下方式访问它:
environment.responseSchema
但是,这将返回null。如何访问我使用postman创建的环境变量。我实现这一点的方式与http://blog.getpostman.com/2017/07/28/api-testing-tips-from-a-postman-professional/提示4: JSON验证是一致的。
发布于 2018-04-19 18:52:04
因此,要明确的是,您添加的是集合变量,而不是环境变量。邮递员变量的更多信息
要访问集合变量,可以在“测试脚本”选项卡中执行pm.variables.get("responseSchema")
。
为了更完整一点,您也应该解析它。
var mySchema = JSON.parse(pm.variables.get("responseSchema"));
console.log(mySchema.properties.firstname.type);
另外,我相信你的目标是无效的,你可能打算这么做。
{
"properties": {
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
},
"phonenumber": {
"type": "integer",
"format": "int64"
}
},
"required": ["firstname", "lastname", "phonenumber"]
}
https://stackoverflow.com/questions/49927750
复制相似问题