Using a conditional for which tests to run in runner

I have a field in a return object called “PRODUCT”. The JSON response returns all items for every product, but I need to execute some tests for some products, and some for others.

response.ProductLongName is the field.

What I would I would like to do is something like:

if (reponse.ProductLongName.contains("product1")) {
  // Set of tests for product 1
} elseif(reponse.ProductLongName.contains("product1")) {
  // Set pf tests for product 2

Thanks in advance!

Hi @davemchughppg

Welcome to the Postman community.

Is your question how to achieve this in Postman or how to write the Postman Scripts?

Thanks! Nice to be here :slight_smile:

My question is how do I test if a JSON response value contains a specific string, and then if it does execute some tests.

I have already created around 40 tests for all of the values, but not all tests should be executed for every runner iteration.

Does that make sense?

Okay. I get you.

You’re already doing this with the conditional statement you have above. What you need to do now is to author these tests within that specific conditional code blocks.

The test scripts are written in JavaScript, so any valid JavaScript code will run there.

I see you already know how to author tests with Postman Scripts but let me know if you need any further help with that.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.