So, this is something that Iโm wondering if it is possible and if so, how to approach it.
So, my idea is that I want to set a variable that would have several different values, like an array I suppose? e.g. Apple, Grape, Cherry , Berry, Orange
And then Iโm thinking of a script that would get on of the above options and set it in a new variable, that would then be used in the body.
After which Iโm wondering whether to run it in a loop, until all values have been used - same api request, just with new value for that variable or maybe I should just run the collection multiple times and be happy with the results?
Anyway, this is more of a question if it is doable.
edit:
To be more precise of what Iโm looking to do, itโs basically like _.random, however for a predefined variable - having 5 strings/numbers that would be randomly picked for each run of the api/collection.
Yes, thank you. This is actually quite helpful.
However Iโm looking to do it without using .setNextRequest.
What Iโm looking to do and will hopefully have it done within an hour of writing this, I will make a variable with different data, which Iโm hoping to extract by targetting data from the array with an index, as I have the array with 4 values , so Iโm going to try to create an index with ._random(0, 3), which should also allow me to test it in the next request by using the same index random value.
Hey, what I meant to do is use Collection Runner with more than one iteration, so for each new iteration that data would be different as most of my variables are array lists and Iโm using ._random to get a different (or the same value if the number is the same) value from the arrays on each run.
Perhaps you should raise your own question instead of adding to a four year old close topic.
You might want to be specific about what you want to do, as the original question here is actually two different things.
One is setting a random variable, and the other is looping through the data set multiple times.
A random variable is easy (using a bit of code in a pre-request script to read a collection/environment variable and to update the request body. Creating a loop requires setNextRequest() and array shift which is a bit harder to setup.
These have different solutions so when you do post your own question, please be as specific as possible in what you would like to achieve.