How to get the index of the current request running within the folder in Postman? - postman

How to get the index of the current request within the folder? Depends on the process I'm performing, there can be more Steps, and sometimes there's no "New" request. I'm planning to create an array within the Pre-Request of the folder and will fetch the override data from there.

Related

Run multiple Pre-request scripts sequentially in postman

I have created a postman collection consisting of around 80-100 requests. And I have categorized them in 5 separate folders. Each folder has its own functionality.
I want the multiple pre-request scripts to be run sequentially for the specific request. What is currently happening is the number of scripts I have in one post-script is running but not in sequence. It runs randomly or not sure how. I would appreciate any help.
Pre Request script execute per request (if its in request) or once for all the reqeusts in the collection if its collection level . You cannot control the flow of pre-request script alone., but you can control what request osend nex use postman.setNextRequest
https://learning.postman.com/docs/running-collections/building-workflows/
This will run pre-reqeust script of that particular request plus send taht request

Using Postman, can initial setup requests be in the same collection as a data file?

Using Postman data files for the first time - I have a couple of setup requests / tests to carry out (authentication, clear cache etc.) just once before a data file gets executed against my functional requests.
Do the setup requests need to be in a separate collection to avoid them being executed against every row of my data file, or can I combine them in the same collection somehow while ensuring (a) they are only run once and (b) they are run before the data file is executed?
We also want to execute this via Newman for our nightly automated run.
I would put all requests in one collection.
The very first script being the setup script.
Then in the pre-request script of the setup, you can check pm.info.iteration:Number to get the number of the current iteration and if it's not the first one, use pm.setNextRequest("2nd request") to call the 2nd request in the collection.

How to reference other collections in postman

Is there a way to reference other collections from a specific collection. For example, if I have a file upload collection (something that uploads a file), I want to be able to use that from other collections. How would I reference the file upload?
Here's an example of what I'm talking about.
I have a collection where a file is uploaded and a calculation needs to be performed. The test or collection would go something like this where each step is a POST, GET, etc
Upload and run calculation:
Generate a token
make call
copy/save token value
Upload specific file (these would be 3 individual requests)
Upload file
Monitor upload status
Return ID of file uploaded
run calculation
use ID to pass as parameter
pass other values to set up calculation
monitor run
validate results
In another collection I need to validate uploaded files metadata is correct. Not directly related to the one above, but has some similarities
Generate a token
make call
copy/save token value
Upload specific file (these would be 3 individual requests)
Upload file
Monitor upload status
Get final result and return ID of file uploaded
Get me
validate metadata is correct.
Steps 1 and 2 are common functionality, there would be no difference there. How could I extract those two steps as modular components or functionality so I can reference them from any collection?
For additional clarity, we use ReadyAPI and are able to do 'Run Test Case' which can obviously run another test case. We've separated the functionality of token and file uploads into it's own test case and use it as a modular component. I'd like to achieve something similar with Postman.
Unfortunately Postman collections are working a little bit different.
But you can Merge your two collections to a single one, and execute it as one single collections.

Using Postman variables across tabs

Postman has been an amazing tool for me, but I have some questions about using variables. In my collection I have 4 tabs/requests.
The first is to get a token that is used in the other three (the token expires after 15 minutes so I have to rerun that request frequently and update the other 3). It needs to be passed in the headers of the other three requests. I'm familiar with the {{variable}} syntax, but I'm not sure how to dynamically set the variable after running the first request.
The second is similar, where I'd like to be able to set a string manually in some central location and use it in all of the requests. For instance, the URL is https://the.api.com/v1/{{someidvalue}}/abc so where can I change that in a single location manually to be reused across the collection?
Thank you!
To change the value based on server response you can use the test feature Postman test script
For exemple
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("Authorization","Bearer " + jsonData.result.accessToken);
The central location that you are looking for is the enviroment postman manage environments

Run next request with new iteration data from json by using setNextRequest in postman

I have a case where i have a folder in a collection which has to run for a specific set of iterations before going to the next folder.
There is no direct feature in postman yet which allows you to set different iterations at each folder level and still run the collection as whole.
I want to run a specific request in a folder with all the testdata i provide in a json and then move to the next request as per the collection folders.
I tried achieving the same using setNextRequest in the same request which has to be run multiple times but with different data.
However, it runs the same data again for the second time as well and through the runner it goes to iteration 2 which was set to 2 at collection level as well.
How can I achieve my usecase.