How I can validate response with the help of global/collection variables

Here’s an outline with best practices for making your inquiry.

My question:
I have a response body with following fields and these values are coming from DB and values changes every time we hit send button(values are dynamic). How can I validate the response in the postman test script.
Please help.
Thanks!

{
“memberId”: 123
“email”: “abc@gmail.com”,
“memberStatusCode”: “CANCEL”,
“isActive”: true,
“joinDate”: “2021-04-09T08:09:08.32+00:00”,
“cancelDate”: “2021-04-09T08:10:03.653+00:00”,
“effectiveCancelDate”: “2021-05-09T08:10:03.653+00:00”,
“primaryCustomIdentifier”: “pendingcancelQA040921”
}

Details (like screenshots):

How I found the problem:

I’ve already tried:

Hi and welcome! :wave:

Could you help me to understand, what are you hoping to validate if the response is random every time?

You mentioned global/collection variables in the title; does this mean that you are setting the values using a POST with random elements (e.g. POST with email: {{$randomEmail}}) and you want to know how to pass these values using variables into a subsequent GET request, so that you can validate that the GET request is bringing back these details?

Thank you for replying. I am trying to validate response which is dynamic and changes each time we hit send button.

{
“memberId”: 123
“email”: “**abc@gmail.com”,
“memberStatusCode”: “CANCEL”,
“isActive”: true,
“joinDate”: “2021-04-09T08:09:08.32+00:00”,
“cancelDate”: “2021-04-09T08:10:03.653+00:00”,
“effectiveCancelDate”: “2021-05-09T08:10:03.653+00:00”,
“primaryCustomIdentifier”: “pendingcancelQA040921
}

The values in bold are unique values each time and I need to validate these in out test scripts/results.

The challenge with validating these values is determining what the ‘expected’ value should be, if they differ each time. Almost anything is possible if the requirements are understood :slight_smile:

For example, joinDate: Would this always be today’s date? Or would it always be X days in the past?

Again, for memberId: Do you simply want to validate that you get any number in the response?

Much of this could be achieved with either Schema validation, or you could write more long-form tests such as the below:

pm.test("Member ID is numeric", function () {
    pm.expect(jsonData.memberId).to.be.a("number");
});
1 Like

Yes Join date could be anything it depends on members joining our site. Is it only possible to validate schema or is there any other way to compare the data as well.