Day 29 - Challenge. Requests added test error

Could someone point me to the root cause of this error?

The test failed, but concole.log prints the same as expected …

Why does it failed ?

That isn’t the part of the test that is failing.

It will be this one.

    let createRequest = folder.item.find(req => { return === "Create Webhook" | === "Create Webhook Copy" })
    pm.expect(, 'check create request name').includes("Create Webhook")
    pm.expect(createRequest.request.method, 'check create request method').equals("POST")
    pm.expect(createRequest.request.url.raw, 'check create request url').includes("")

You are right - after I have renamed 2nd request to “Create Webhook” - test was passed.
Could you please give a hint - how you are recongnised error line ?
Where it placed?

In this instance, it was failing to find a variable called “name”.

The failing test will tell you which test block has failed, but its not always obvious which line has caused the failure, so its a case of looking at any element that is using a “name” variable, and there are three in that test, one for each folder.

Once you know its related to the folder queries. In this instance, it was just a simple check against the screenshot and it quickly become apparent that it was the request name that didn’t match. It’s not always that easy to spot.

Other troubleshooting steps would be to add console logs similar to what you tried to do. Just to see if you are getting to that part of the code. As soon as an assertion in a test block fails, it will stop executing any other code in that block. So using the console logs is a good way to find out if you have hit a particular piece of code or if its errored before the particular line you are looking at.

It is sad to hear that there is no such feature in Postman for tracing errors.
But in any case, thanks for the explanation.

This is down to the tests you write (or in this case, how Postman have written the tests).

You can always add extra console logs, or refine the tests so they are a bit more explicit on what is failing, but that would be down to whoever is writing the tests.

For example, in the previous code block.

let createRequest = folder.item.find(req => { return === "Create Webhook" | === "Create Webhook Copy" })

I would probably create an assertion right after this line of code checking that the createRequest variable is not undefined before I try and use that variable in any subsequent assertions.

pm.expect(, 'check create request name').includes("Create Webhook")

The problem with the above test block is that if the createRequest variable is undefined then it throws a type error and breaks the pm.expect assertion function instead of showing the text in the assertion which is what I think the developer wanted to happen. It’s meant to show “check create request name” in the error message so you know which assertion has failed, but is showing the generic type error instead.

Therefore in this instance, I would suggest minor improvements to the test code would prevent the need for more advanced troubleshooting. Which is sort of what you want out of your tests. A well crafted test should tell you what is wrong without the need for onerous troubleshooting.

Thanks for your help.
Challenge done - badge taken.

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