Day 8 - Validate your solution in Newman

I have submitted successfully the folder through postman runner.

But using CLI, it is showing errors

plz guide if I can use in CLI : --env-var for postman api key?

That is a rather unique way of checking for a 200 status code.

In your request, you have…

pm.test("Test for Request 1", function () {
    // Perform tests for Request 1
    pm.environment.set("request1_result", pm.response.code);

Please note, you have a test block without any assertions. (The actual tests). The setting of the environment variable does not need to be wrapped in a test block. (The environment variable is not needed though).

You then run the following tests for each request (using the folder tests tab)

pm.test("Status code is 200", function () {

pm.test("Status code is 200", function () {

When the first request is run, then request2 will not have a value, hence the errors.

It’s running ok in the Postman app because you have probably run this a few times and the values are there from the previous runs.

Not sure where you learnt this from, as this is not how the Learning Centre shows you how to do this.

Which is simply…

pm.test('Status code is 200', () => {;    
1 Like

Thanks, I understood it in a wrong way and makes it complicated checking the simple status code 200.
Corrected both day 7 and Day 8, it passed without any issues.

Hello @michaelderekjones, on submission of 15 days challenge I am getting submission failed for day8 so I again tried to submit through CLI and it shows me error as

Let me understand why postman collection runner is not showing any error but CLI shows, whereas I have deleted all the runner results in postman and then only run the collection again.
and guide me where I need to recitfy.

The assertion error is pretty much telling you what is wrong.

It was expecting a 200 ok status code, but returned a 401 unauthorised instead.

Re-read the documentation from day 8. In particular the last sentence in step 5.

It is expected that a few tests fail in the last folder, but not in the first folder.

It’s failing as you are running the entire collection including the “Submit your solution” folder and its failing the authentication for the submit request. This is expected behaviour.

If you follow the instructions in step 6 to run just the “Output test results” folder, you should no longer have any failing tests.

Please help me here for

this instruction is run entire collection.
sorry if I understood it incorrectly.

Think about the error message and the failing test. A well designed test is crafted to tell you what the issue is without you having to spend a lot of time trying to troubleshoot.

In this circumstance, it’s failing the authentication. Therefore how have you setup the authentication. I’ll give you an hint; “X-Api-key”.

You never shared the Newman command line that you are running but have you included the environment file with the collection_uid variable in the Newman command line parameters?

The whole point with these challenges are that they are meant to be challenging.

The early ones pretty much tell you all of the steps, but the later ones requires you to look up available resources to work out how to achieve the task.

Telling you the answer will diminish the learning.

The challenge advises the following;

There’s many ways to handle sensitive information locally while running Newman, but be careful not to expose your secrets in your public workspace.

This means that the API key value should not be in the exported collection or environment. (As the API keys are confidential information and the workspace is set to public). Current values are not exported by the way so you will have a variable with a blank value.

Therefore I recommend you re-read the documentation in relation to the Newman command line options and see how else you might do this.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.