Day 26th -parse html response-I am able to create an array and store the values of the response in an array it passes individually when i run the test case. But when i run it in submit the test case gets failed stating that cannot read property ‘find’ of undefined. Can anyone help me out .
Can you double check that your collection variable is being created and that the value is persisted both the “initial value” and “current value” columns?
When I recreated your solution, I got a different error: “JSONError: No data, empty input at 1:1 ^”. After I persisted the “links” collection variable’s value to be in both the initial and current columns, the validation test passed. However, when I delete the collection variable altogether, I get the error you’re showing, so it seems like maybe your collection variable isn’t being created. Hope this helps!
Hi! Could you expain why do you use JSON.stringify in this case: pm.collectionVariables.set(‘links’, JSON.stringify(links)) ?
When variable “links” is already an array? Why would you make it as a string?
But I see that when setting this array to collection variable Postman does not see it as array. How come?
You need to stringify() arrays when storing them as collection\environment variables and then JSON.parse() them when retrieving or they end up being treated as strings not arrays.
It’s the same principle when parsing the response. If you didn’t parse it, and just retrieved the body it would just be a JSON object wrapped in a string.