Day 09/15 days of Postman - for testers - I am stuck at Day 9 :(

If anyone can help me with Day 9 collection for the 15 Day Challenge for testers that will be great!!

Details (like screenshots):

How I found the problem:

I’ve already tried:

Stuck where? You’ll need to tell us a bit more than that.

As per the advice template when posting questions shows.

Details (like screenshots):

How I found the problem:

I’ve already tried:

Include screenshots, and what you’ve already tried.

If someone can guide me through this

  1. Add test scripts :
  • Add a test to verify a 200 status code
  • Add a script to get the variable pageNumber and increment it by 1, only if the next page is available
  • Save the variable so the incremented value can be used in the subsequent API callSend the call to make sure you are getting and setting the pageNumber variable as expected. Remember you can use the console for more visibility if your code isn’t behaving as expected.
  • Add another script to set the next request called to be the get starships request if the next page is available, so that running this folder in its entirety would page through all the starships in order until there are no more pages available.
  1. Add another test script : Still under the Tests tab of the get starships request, add code to loop through the starships and determine which starship is the fastest.
  • Initialize two collection variables called fastestShip and fastestSpeed . The INITIAL values can be your first name and 0 .
  • You must cast a string to a number to compare numerical values, like speed.
  • Keep track of the fastest starship’s name and max_atmosphering_speed as collection variables, to use in the next step.

The 15 days of Postman course is a bit harder that the Galaxy 101 but the principles are the same.

They aren’t designed to catch you out. The 15 days is designed to test your knowledge. There is an assumption that you know most of the basics.

The instructions for this day are detailed as you have posted.

What have you tried so far? What part of your stuck on?
We can’t give you the whole answer as that would defeat the purpose of the challenge.

You will understand the mechanics a lot better when things go wrong and you have to fix them.

All of the steps you listed above, are covered in the Galaxy 101 training.

If you are stuck in a particular part, you need to post what code you’ve got so far and then we might be able to help without telling you the whole answer.

So, I need help in the part where you need to find the fastestShip and fastestSpeed. I am able to create an array for all the starships and speed but not sure how to add the logic to get the fastestSpeed and StarShip name.

Have you gone through the Postman Galaxy 101 course yet?

The logic for most of this is covered in this course.

Postman uses JavaScript under the hood so w3Schools is a good starting place for any elements that you may struggle with.

The results should be an array, which you will need to combine with a forEach loop.

JavaScript Arrays (w3schools.com)

JavaScript Array forEach() Method (w3schools.com)

If you are struggling, you need to post the code you’ve tried so far.

Hi, I’m stuck at day 09 in loop function 3.1 *Add another script to set the next request called to be the get starships request if the next page is available, so that running this folder in its entirety would page through all the starships in order until there are no more pages available. I try to learn APIs 101 course but still cannot resolve the challenge. Could you please help me? Tks.

@duclehoai2

You need to post what code you currently have and where you are having issues.

If you do post code, please use the preformatted text option in the editor so that its doesn’t all get aligned to the left.

This is my script in test tab

// Verify 200 status code
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
const response = pm.response.json();
let nextRequest = response.next;

pm.variables.set('nextRequest', nextRequest);
var pageNumber = pm.collectionVariables.get("pageNumber");
if(nextRequest !== null){
    pageNumber++;
    pm.collectionVariables.set('pageNumber', pageNumber);
}

And my script in pre-request Script tab

let nextRequest = pm.variables.get('nextRequest');
if(nextRequest !== null){
    postman.setNextRequest('get starships');
}else{
    postman.setNextRequest(null);
}

I use the collection run to iterate data from respond body. Is that right?

@duclehoai2

Nothing is needed in the pre-request tab for this challenge.

I’ll go through the logic, so you can break down your code.

Step 1. Parse response.
Step 2. Console log the response count.
Step 3. Test the status code.
Step 4. Define a current speed variable from the fastestSpeed collection variable.
Step 5. Loop through the results (for each ship). You need an IF statement that sets the ship name and current speed if the current ship is faster than the current speed.
Step 6. Get the current page number from the collection variable.
Step 7. If response.next is not null, then increment the page number and re-save it to the collection variable, and then use postman sexNextRequest to re-run the same request. The page number is parameterized in the URL.