簡體   English   中英

在 Postman 測試腳本中使用 IF/ELSE

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM