I am using Postman in order to test, But I am stuck on using if/else in the scripts.
My goal is to test if a property is visible in the response body. if the property is not there, I want postman to expect it be empty. and move on to the next test. The properties are nested in an array.
This is what I came up with so far.:
//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');}
});
However, the test always "fails" if the array is not empty. How do I go about this, it might be something small that have I placed incorrectly in the test, but I cant quite figure it out.
Figured it out:
pm.test("Test if correct sub properties rijbewijs are sent", () => {
if ((matchesVacatures.rijbewijs).length !== 0)
{pm.expect(matchesVacatures.rijbewijs[0]).to.have.property('codeSoortRijbewijs');}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.