Extract value from a JSON Response Body via the Test Scripts - no output

I have a response with the following format

{
    "records": [
        {
            "timeStamp": "xxxxxx",
            "spaceName": "xxxxxxx",
            "spaceId": "xxxxxx",
            "type": "xxxxx",
            "message": "xxxxx",
            "user": "xxxxx"
        },
    

I want to extract a list of the users to use in another get request.

In my Tests script, I’ve got the following

let responseData=pm.response.json();
console.log(responseData);
pm.environment.set("user", responseData.records[0].user);

However when I hit send and run the request, i’m not getting any output in my ‘Test Results’ however it isn’t throwing an error either, any ideas?

Test Results (in the results panel) will only have something in it if you have a pm.test() method. Do you check your Variables tab to see that your environment variable is set to the 0th user?

Hi David

Figured it out thanks!

pm.test("Collect User Record", function () {
responseData = JSON.parse(responseBody)
value = responseData.records[0].user
console.log(value)
pm.environment.set("user", responseData.records[0].user)
});
1 Like