Guys, thanks a lot… you got me to a point where I have a script, that is doing what I want it to do.
Now I just have one question left, which is less technical (hopefully):
Every request is responding with a JSON file with the wanted information. How can I save these responses during the loop … or… where can I find it?
After the successful run of the Runner I can choose -> Export Results. But this is giving me a report of the run (i.e. running time etc.).
How can I find the actual responses of the API?
If someone is interested here the code that works:
Pre-request:
// Load the latitude and longitude arrays from the environment
const latitudeArray = JSON.parse(pm.environment.get('latitudeArray')); // Parse from string to array
const longitudeArray = JSON.parse(pm.environment.get('longitudeArray'));
// Check array by log.output
console.log(latitudeArray)
// Load the current index
const index = parseInt(pm.environment.get('latLongIndex')); //Parse from string to Integer
// Some log.outputs to follow what's happening
console.log("The value of the index is " + index);
console.log((index+1)+". entry of array: "+ parseFloat(latitudeArray[index]));
// Set the variables for this iteration and increment the counter
pm.environment.set('latitude', parseFloat(latitudeArray[index]));
pm.environment.set('longitude', parseFloat(longitudeArray[index]));
pm.environment.set('latLongIndex', (index+1));
Test:
const latitudeArray = JSON.parse(pm.environment.get('latitudeArray'));
const longitudeArray = JSON.parse(pm.environment.get('longitudeArray'));
const index = parseInt(pm.environment.get('latLongIndex'));
// Check to see if we need to do another loop
if(index < latitudeArray.length && index < longitudeArray.length) {
// If another loop is required, set the next request to this one.
postman.setNextRequest("RequestName");
}
else {
// If another loop is not required, set index back to 0 for next time.
pm.environment.set('latLongIndex', 0);
}