Day 26 challenge -Script added correctly | TypeError: Cannot read property 'find' of undefined

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 .

image

1 Like

Hi @kkalpana55,

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 @carson-hunter-postma yes its was not creating I changed few steps now its not getting error thank you very much

1 Like

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?

@spaceflight-astronom

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.

1 Like

Great, thanks. I never thought of these specifications for Postman :slight_smile: