Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OR operator in Postman Response Tests

Tags:

postman

I have the following assertion in my postman script test, but for some reason the tests are failing when one of the following is missing: Lease, Finance, or cash in my response body. Is the "||" not the OR operator?

tests["Deal Type"] = responseBody.has("Lease" || "Finance" || "Cash");
like image 902
Arsenii Avatar asked Oct 04 '17 20:10

Arsenii


People also ask

How do you check body response in Postman?

The Postman Body tab gives you several tools to help you understand the response quickly. You can view the body in one of four views: Pretty, Raw, Preview, and Visualize. in the results pane. You can also place your cursor in the response and select ⌘+F or Ctrl+F.

How do you assert a response to the Postman?

In Postman, we can write the assertion in many ways. One of the simplest ways is the snippets, which are nothing but a block of codes that have some unique functions inside it and are available in the postman app. Users can easily access the snippets and can get the code inside the tests editor and run the test.


3 Answers

It should be something like:

pm.expect(pm.response.code).to.be.oneOf([201,202]);
like image 172
idefixcert Avatar answered Jan 03 '23 23:01

idefixcert


According to the postman docs the correct syntax would be

tests["Deal Type"] = responseBody.has("Lease") || responseBody.has("Finance") || responseBody.has("Cash");
like image 27
Paaz Avatar answered Jan 03 '23 23:01

Paaz


Write it is like this..

pm.expect(pm.response.data[0].DealType).to.be.oneOf(['Lease', 'Finance','Cash']);
like image 26
Surbhi Singh Avatar answered Jan 03 '23 23:01

Surbhi Singh