When sending my request manually it runs correctly and all the test is Pass.
But when I run the same with scheduled runs or CLI it shows error in the request-
TypeError Cannot read properties of undefined (reading ‘id’)
at test-script
inside “End to End API Testing / Create story issue type in new project / Get all
projects”
As much I understood there is no problem with test-script as the it is executing correctly when sent manually. But when running with Postman CLI, the response body is not being correctly returned or there is some problem in storing/parsing of it.
First of all, you don’t have any tests in that script.
It’s just code in the tests tab. Semantics, but an important aspect.
Usually, you would parse the response, and then have an actual test checking for the response code or that the elements you want to set as collection variables actually exist before you set the collection variables.
This would give you a better understanding on what is failing. Rather than receiving a generic TypeError because it can’t find the element in the response.
It’s the setting of the collection variables that is erroring because it can’t find the ID element.
Do you not get to see the results of the console logs somewhere in the CLI? Or is that API just returning two blank arrays?
Is “indexofsecondproject” a variable, or is it just something your showing us here? Shouldn’t it be a 0 or 1?
Ideally want to console log the response and ensure those elements are being returned or wrap your code in tests. Either should provide you the feedback you need to troubleshoot where this is failing.
Firstly, you are correct there is no test in the code, it is a code for setting a collection variable from the response body.
The response when parsed through the method pm.response.json(), returns an
arrray JS objects/attributes, and when logged I can see the response body in console as well.
‘indexofsecondproject’ is a variable (basically its the index of “secondProject” in the project names array). I missed a line, now I have corrected that, you can recheck the code for clarification.
I can see the console logs in CLI but the API is returning blank array, though the same API is returning correct array(not blank) when request is sent manually.
@michaelderekjones
Thank You for your support I was able to resolve the problem.
On logging the whole response, I observed that the response body was appearing incorrect as I was using global variable for auth token . So, there was restriction.