# Using a conditional for which tests to run in runner

**URL:** <https://community.postman.com/t/using-a-conditional-for-which-tests-to-run-in-runner/59087>\
**Category:** Help Hub\
**Tags:** tests, runner\
**Created:** [March 21, 2024, 12:32pm UTC](https://community.postman.com/t/using-a-conditional-for-which-tests-to-run-in-runner/59087 "2024-03-21T12:32:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davemchughppg](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@davemchughppg](https://community.postman.com/u/davemchughppg)\
**Post date:** [March 21, 2024, 12:32pm UTC](https://community.postman.com/t/using-a-conditional-for-which-tests-to-run-in-runner/59087/1 "2024-03-21T12:32:53Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [March 21, 2024, 12:41pm UTC](https://community.postman.com/t/using-a-conditional-for-which-tests-to-run-in-runner/59087/2 "2024-03-21T12:41:55Z")

</div>

Hi @davemchughppg

Welcome to the Postman community.

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

---

<div class="post-metadata">

**Author:** ![davemchughppg](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@davemchughppg](https://community.postman.com/u/davemchughppg)\
**Post date:** [March 21, 2024, 1:30pm UTC](https://community.postman.com/t/using-a-conditional-for-which-tests-to-run-in-runner/59087/3 "2024-03-21T13:30:21Z")

</div>

Thanks! Nice to be here 🙂

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?

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [March 21, 2024, 1:51pm UTC](https://community.postman.com/t/using-a-conditional-for-which-tests-to-run-in-runner/59087/4 "2024-03-21T13:51:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 24, 2024, 1:52pm UTC](https://community.postman.com/t/using-a-conditional-for-which-tests-to-run-in-runner/59087/5 "2024-03-24T13:52:39Z")

</div>

Closed on March 24, 2024, 1:52pm UTC

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