Hey guys. I want to run one request with different values of query which was set as variables. For example, I have to variable (query params) {{from}} and {{to}} I expect: from = [“2020-12-08”,“2020-12-09”,“2020-12-13”] and same for ‘to’ : [“2020-12-08”,“2020-12-09”,“2020-12-13”] . And I want to execute request many times. It will be three tests for 1 request with different values:
{{baseUrl}}/ui/?dateFromStr=2020-12-08&dateToStr=2020-12-08
{{baseUrl}}/ui/?dateFromStr=2020-12-09&dateToStr=2020-07-09
{{baseUrl}}/ui/?dateFromStr=2020-12-13&dateToStr=2020-07-13
I did this , but in console I see null for parametrs : from and to.
/uuu?dateFromStr=&dateToStr=
UPD: When I added values for variables and now in console :
?dateFromStr=[%222020-07-12%22,%222020-07-15%22]&dateToStr=[%222020-07-12%22,%222020-07-15%22]
The sendNextRequest should be the name of the saved request and not the URL like you have it. Unless that is the actual name of your request
To loop over that same request, you could use postman.setNextRequest(pm.info.requestName)
It looks like the rest of the code has been taken from a different usecase and adapted with your variable names to suit your needs. I haven’t run this locally so I don’t know what’s going on just by looking at it.
I would suggest that if you have any code in your examples, paste the raw code in a code block rather than an image of the code.
This makes it easier for folks to copy and paste it into thier own Postman instance, you can’t do that with a picture.
var from = pm.environment.get("from");
var to = pm.environment.get("to");
// if(!from){
// from = ["2020-07-12","2020-07-15"];
// to = ["2020-07-12","2020-07-15"];}
var currentFromDate = from.shift();
pm.environment.set("fd",currentFromDate);
pm.environment.set("from",from);
var currentToDate = to.shift();
pm.environment.set("td",currentToDate);
pm.environment.set("to",to);
And Test tab:
var to = pm.environment.get("to")
if(from && from.length > 0)
{
postman.setNextRequest(pm.info.requestName);
}
else{
postman.setNextRequest(null);
}
If you’re only iterating over a set of known values for the two dates, could you just add them to a data file and use that in the runner to resolve those variables in the URL.
It would remove the need to shift those values in the script.
We use AWS pipeline (Newman) I don’t run this request via Postman in Collection Runner. If as you wrote about data file it possible for my case run via pipeline (Newman) so can you tell me how I can do this
Using the data file with Newman or using the code that you have found and tried to use within your collection?
The data file can be referenced in the Newman command, on each iteration it will resolve the variables in the Collection, if these matched the key/column header in the file.
You wouldn’t need any of that code in the scripts.
Did you write that code from scratch and know exactly what each part of that is doing?
I don’t understand you… Okay can you give me example how I have to record values in json file. I have GET method! Where me need add file??? I saw many examples with file but every has POST and in body they select file. Hey
It doesn’t matter what method the request is - the values from the datafile will resolve the variables in the Collection file that use the {{..}} syntax - These could be anywhere in the Collection (URL, params, headers, request body, etc).
Okay but How they know that they have to set on place {{from}} and {{to}} variables?
And in your example above they set count of Iteration in Collection runner, but I told you , that I don’t use Postman
The iteration count is automatically taken from the number of items in the data file.
If you have 1 item it will run once, if you have 15 items it will run 15 times. Etc.
There seems to be a lot of frustration from your part on this, if you just actually use the data file with Newman and see it for yourself, things will be a lot clearer.