Day 10: Test coverage

Hey guy, please I need help. In the second challenge request day 10, the training asks me to add these details:

  • POST method
  • httpbin.org/{{path}} request URL and
    Notice we are referencing a variable that is still undefined in the request URL.
    Once again, let’s add some test data.

I want to know where I’m suppose to generate this path because I thought that at the end of the documentation I’d have to be asked this and I’m supposed to add a test called Response has data value to ensure the data returned from the server is the same as the test data submitted in the request.

What to do please?

Hey @science-engineer-650 :wave:

What have you done so far?

Can you share the URL of your Public Workspace please?

Hint: This is the relevant part of the exercise.

Create data file: In the next steps, we use a data file to pass Postman sets of values to use in a collection run. Save this data as a local file.

Thank you for your post.
I may write that when you find the answer to the third question in section 4 you sort out Day10. Again, when I read the challenge the {{path}} is not required to move to the next day. Whilst submitting your collection, you may see that the {{path}} is not check in the test script.
In short, providing a solution to the third question in section 4 helps to figure out the idea behind that challenge. From my point of view, an undefined variable could be filled in manually or through …

Thank you very much. I understood that this was really the key to this challenge; but I have another problem with question 4 in section 4.

here is the script I wrote:

pm.test("Response has data value", () => {

   const value = pm.iterationData.get("value");
   pm.collectionVariables.set("testData", value);
   const responseV =  JSON.parse(pm.response.json().data).value
   console.log('Val: ', Number(responseV))
  pm.expect(value).to.eql(responseV);
})

But when I run my collection I have test failures that I’d like to understand why and how I can have a solution for. under you will see my test failure picture

@science-engineer-650

This will be the best way for others to see what you have in front of you. :pray:

This is what an example request\response should look like for this challenge.

You need a simple pm.expect assertion.

That checks the “value” key from the data file against the testData key in the response.

So my question back to you is “where is the testData key in the response?”

THANKS :pray:

My testData is in the " Params Tab"

here is my answer in the console

Not sure what you have done there.

There shouldn’t be a request body for the request if its using query parameters.

  • Once again, let’s add some test data.

  • Under the Params tab add a parameter called testData with the value {{value}} to reference the property value in the data file. This variable is also still undefined.

  • Under the Tests tab, add a test called Response has data value to ensure the data returned from the server is the same as the test data submitted in the request.

Your post URL looks ok. I suspect that because of the request body, the response is not the same as what I posted earlier.

You also didn’t expand the response body in that last screenshot which would have been useful information to see.

As Danny mentioned earlier. If you share your collection, its much easier to troubleshoot.

@science-engineer-650 Again thank you for your post.
When I saw your test you will be confronted to a closure issue with the Postman interpreter.

You shall generate the const value outside the test function.

Also, you may set a collection variable separately from the test function rather than nested the setter inside the test function.

I added a screenshot of my solution hoping to help.

This challenge isn’t that complex.

The issue here is that the original poster is somehow sending a JSON body and a query parameter, when it should just be a query parameter for the page number.

The instructions tell you use a query parameter.

Under the Params tab add a parameter called testData with the value {{value}} to reference the property value in the data file. This variable is also still undefined.

httpbin is similar to Postman Echo in that it basically returns back what was sent.

If you send a JSON body, then the details will be under the data element in the response. If you just send a query parameter, it will be under the args element in the response. So its important to get this right.

There should also be a path variable in the URL (which also comes from the JSON data file used in the collection runner, although all it does is change {{path}} to POST.

Once you have the request crafted correctly, returning the appropriate JSON then the tests are very simple.

  1. Status code is 200
  2. Expect Response.args.testData to equal iterationData(“value”).

I haven’t provided the exact code, as that would defeat the purpose of the challenge.

But you don’t need to be saving anything to environment variables or check or 400 statuses.