[英]Using IF/ELSE in Postman Test scripts
我正在使用 Postman 进行测试,但我坚持在脚本中使用 if/else。
我的目标是测试一个属性在响应正文中是否可见。 如果该属性不存在,我希望 postman 期望它为空。 并继续下一个测试。 属性嵌套在一个数组中。
这是我到目前为止想出的:
//Test of correct sub properties rijbewijs zijn meegestuurd
pm.test("Test if correct sub properties rijbewijs are sent", () => {
if (pm.expect(matchesVacatures.rijbewijs).to.be.empty);
else { pm.expect(matchesRijbewijs).to.have.property('codeSoortRijbewijs');}
});
但是,如果数组不为空,测试总是“失败”。 我该如何 go 关于这个,这可能是我在测试中放置错误的小东西,但我无法弄清楚。
弄清楚了:
pm.test("Test if correct sub properties rijbewijs are sent", () => {
if ((matchesVacatures.rijbewijs).length !== 0)
{pm.expect(matchesVacatures.rijbewijs[0]).to.have.property('codeSoortRijbewijs');}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.