Hello from Turkey Mike,
I would like to ask what is wrong with my code. Because as I checked your reply about Day09 , all the code starts if there is a next page which means “if next page is not null”. I have put some breakpoints to see where exactly the action is and to check if everything is correct. Please kindly check my code (I know there are many lines because I added some logging statements and some collection variables to see the action breakpoints.)
pm.test(“Status code is 200”, function () {
pm.response.to.have.status(200);
});
const nextPageUrl = pm.response.json().next;
const starships = pm.response.json().results;
console.log(“Total Num of starships:” + starships.length);
pm.collectionVariables.set(“fastestShip”, “Sara”);
pm.collectionVariables.set(“fastestSpeed”, 0);
pm.collectionVariables.set(“pageNumber”, 1);
var jsonData=pm.response.json();
pm.collectionVariables.set(“totalShips”, 0); // Initialize totalShips variable
if (nextPageUrl) {
for (const starship of starships) {
const speed = Number(starship.max_atmosphering_speed);
if (speed > pm.collectionVariables.get(“fastestSpeed”)) {
pm.collectionVariables.set(“fastestShip”, starship.name);
pm.collectionVariables.set(“fastestSpeed”, speed);
let currentPageNumber = pm.collectionVariables.get(“pageNumber”);
currentPageNumber++;
pm.collectionVariables.set(“pageNumber”, currentPageNumber);
let currentStarshipNumber= pm.collectionVariables.get(“totalShips”);
currentStarshipNumber+=starships.length;
pm.collectionVariables.set(“totalShips”, currentStarshipNumber);
console.log(“Fastest Starship in This Page:”, pm.collectionVariables.get(“fastestShip”));
console.log(“Fastest Speed in This Page:”, pm.collectionVariables.get(“fastestSpeed”));
console.log(“Total Num Of Starships:” + currentStarshipNumber);
console.log("Current page Number: " + currentPageNumber)
console.log(“Next Page Available:”, nextPageUrl);
pm.execution.setNextRequest(“get starships”);
} else {
console.log(“No Next Page Available”);
break;
}
}
}
Thanks in advance for your time and help.
Mike Jones via Postman Community <notifications@getpostman.discoursemail.com>, 28 May 2024 Sal, 12:23 tarihinde şunu yazdı: