Reputation: 1542
I am attempting to create a test that checks a json
response to contain either one property or another.
My example:
pm.expect(jsonData.data.owner).to.have.property('orgName') ||
pm.expect(jsonData.data.owner).to.have.property('firstName')
I can't seem to find any documentation on using or
operators in the new pm.expect()
syntax.
Upvotes: 4
Views: 13228
Reputation: 111
pm.expect( booleanCondition1 || booleanCondition2 ).to.be.true
Upvotes: 1
Reputation: 264
use oneOf()
method
pm.expect(jsonData.carrierType.type).to.be.oneOf(["mobile", "landline"]);
Upvotes: 7
Reputation: 448
I was looking for answer to implement OR in postman tests, but didn't found any. I've done just a simple if statement to determine which of the conditions should be checked. (Knowing the business logic). In my application I had to check if we support german language, but if we don't by default we set it to english. It was easy because I've took the value from my json and than manualy check which condition should be the valid one. This might help you and anyone else in further implementation of this. So for me it looked like this:
pm.test("German language support.", function(){
var jsonData = pm.response.json();
if(jsonData.count() > 0){
var langCode = jsonData[0].language.code;
if(langCode === "en"){
pm.expect(jsonData[0].language.code).to.eql("en") ;
}else{
pm.expect(jsonData[0].language.code).to.eql("de")
}
}
});
Upvotes: 2