I am still new to postman and JSON and get confused easily what is an array/object and how to correctly work with them.
I have a test script which works
let jsonData = pm.response.json()
pm.environment.set(āUserVarā, pm.response.json()[0].member.criteria.children[3].key.sourceId);
This works and pulls a value like this
2c9180897a5eb28b017a
but what I want to achieve - I want to create a Test which tell me if that value is located anywhere in any of the response: 2c9180897a5eb28b017a
I tried many thingsā¦ but the one I feel is closest, I tried the following but it does NOT work it gives me an āAssertionError: Target cannot be null or undefined.ā
pm.test(āTest to find valueā, () => {
pm.expect(jsonData.key).have.property(āsourceIdā, ā2c9180897a5eb28b017aā);
});
I couldnāt get that to work @cmnazario
But thank you for the help.
I did find a solution, so Iām going to post it, to hopefully help someone else in the future.
Rather than searching through objects and arrays and confusing myself what-is-what.
It will output in the console āsuccessā if it finds the string
It outputs a big red error in the fail scenario
āerror in evaluating the test script: AssertionError: expectedā
But honestlyā¦ I spent enough time on this for nowā¦ so this works fine for what I was trying to achieve.