Within my Postman collection I have a lot of variables that are set/get during execution of the requests. For example Customer ID. Each time a customer is created, the Customer ID variable is updated (to a new number) and then a GET is run to return that customers details based on that new Customer ID.
When I export the collection from Postman, it has the latest Customer ID hardcoded in the JSON. Let’s say number 355.
Is Newman “smart enough” to replace that variable with a new one during the cmd-line execution POST of a new customer (number 356), and then use the new value for the GET request that follows? Or is it literally just reading the old/hardcoded values from the JSON file and using those?
Newman will run the requests in order, so if a request is updating the collection variable, then that is what should be used in subsequent requests.
Just remove the value from the variables that get set during execution before you export it so that the collection JSON doesn’t have the value already set. This should prove it to you.
Ah, good to know. Thanks. When I tried this in the past I didn’t remove the variable values from the JSON file and it never worked correctly.
So, I have some variables that are static by design, I should leave those values alone correct? I am assuming I replace strings with empty strings? What about integers/numbers? Can I leave a blank value?
Or are you saying to remove the values within the Postman tool itself, rather than the JSON file?
Just remove any values that aren’t hardcoded or static.
You don’t need to have any value, string or otherwise if your pre-request script or a previous request is setting it.
In fact, you can probably remove the entire variable, because if your script sets a collection variable that doesn’t exist, it will create it at that point in time.