0

I am working on a postman collection where I have written two get requests for APIs. I am using a single data file in the runner for both the requests when I run. My data file looks like below -

enter image description here

What I am trying to do is when I run request1 it should use Algo_id and use in the query parameter and for request2 it should use product_ids. When I run these request from the test runner using data file it runs the requests for the blank values as well, four requests each. I want to skip the runs for blank values and only run it when there is a value in the column for the request.

I want to run both the request two times and skip for the blank ones.

what I have tried so far, but had no success -

request1 Pre-request script -

enter image description here

request2 Pre-request script -

enter image description here

Rohit
  • 1,520
  • 2
  • 17
  • 36
  • What does `pm.iterationData.get("product_ids")` return? If it's empty is it null or an empty string? In either case neither is a boolean so i'm not sure what the expression will evaluate to. – so cal cheesehead Jul 21 '20 at 18:20
  • it returns some symbol, when I hover over it it shows `Empty String`. I have also tried to use 'NA' instead of leaving the value blank and then checking `pm.iterationData.get("product_ids") === 'NA'` but that too does not work.. it goes inside the if but does nothing. – Rohit Jul 21 '20 at 18:28
  • Thinking about it the setup seems a little odd, does request2 depend on the response from request1 or why the empty values? Could you use some known bad value instead of blank? – so cal cheesehead Jul 21 '20 at 21:54
  • I can but the idea is to use a single data file for multiple request. If param value is not for the request the it should be skipped – Rohit Jul 22 '20 at 06:18
  • I don't really see a way to do what you're trying to do, setting the next request in the pre-request script will do that but your request, the current request is still going to execute at which point you already have an empty value to work with. You would need to execute the request and let it be an error state which would generate a lot of unnecessary errors imo. – so cal cheesehead Jul 22 '20 at 18:37

1 Answers1

1

I think what you're trying to do is something that isn't currently supported which is basically if a test condition fails in the pre-request script then abort the current request and go to the next. In your case if there is an empty value found for the url parameter then don't execute.

https://github.com/postmanlabs/postman-app-support/issues/7166

so cal cheesehead
  • 2,515
  • 4
  • 29
  • 50
  • 1
    Yes, I think the same. I have however moved ahead with skipping the test itself based on the value, this way I let the request run but don’t run the tests. – Rohit Jul 22 '20 at 21:34