How to assert multiple value like more than 10k values?

Hi,
my response returns more than 10k values and i have to assert them with expected values.
If there are few, we can test them line by line like:
ex:
pm.expect(pm.globals.get(“Actualvalue1”)).to.equal(pm.globals.get(“Expectedvalue1”));
pm.expect(pm.globals.get(“Actualvalue2”)).to.equal(pm.globals.get(“Expectedvalue2”));

what if we have more then 10k values?
If i save them in a file then compare two files, in the case there is an error, the test will fail but i will have to check line by line for errors.
What is the best solution?
Thank you

Strange case, 10k values… are they unique? or its just a true/false? Can you provide some examples of responses?

You see these values? there are more than 10 000 values.
each is differents.
like
Atualvalue1 = abc123
Actualvalue2 = qwe321
…
…
what i did is to save the response body in a variable and then parse for each value.

pm.expect(pm.globals.get(“Actualvalue1”)).to.equal(pm.globals.get(“Expectedvalue1”));
pm.expect(pm.globals.get(“Actualvalue2”)).to.equal(pm.globals.get(“Expectedvalue2”));

How does the values look like in response

The response is like:

[
{
“City”: “Paris”,
“Name”: “Bastille”
“Place”: “Rue”,
“France”: “true”,
“SpeedLimit”: “true”
},
{
“City”: “Tokyo”,
“Name”: “Tomo”
“Place”: “Rue”,
“France”: “false”,
“SpeedLimit”: “false”
},
{
“City”: “Santiago”,
“Name”: “Hall Brooks”
“Place”: “calle”,
“Panama”: “true”,
“SpeedLimit”: “true”
}
]

Here i put only 3 data.
In the real example there are more than ten thousand data.
i need to validate each data like:
The first City == Paris
The second City == Tokyo
The first Name == Paris
The second Name == Tomo
…

actualResponse = [

    {

        "City": "Paris",

        "Name": "Bastille",

        "Place": "Rue",

        "France": "true",

        "SpeedLimit": "true"

    },

    {

        "City": "Tokyo",

        "Name": "Tomo",

        "Place": "Rue",

        "France": "false",

        "SpeedLimit": "false"

    },

    {

        "City": "Santiago",

        "Name": "Hall Brooks",

        "Place": "calle",

        "Panama": "true",

        "SpeedLimit": "true"

    }

]

expectedResponse = [

    {

        "City": "Paris",

        "Name": "Bastille"

    },

    {

        "City": "Tokyo",

        "Name": "Tomo"

    },

    {

        "City": "Santiago",

        "Name": "H Brooks"

    }

]

let output = actualResponse.filter(function callbackFn(element, index, array) {

    if (element["City"] === expectedResponse[index]["City"] && element["Name"] === expectedResponse[index]["Name"]) {

        return false

    } else {

        console.log(`There was unequal values at the index location ${index} `)

        console.log("value : " + JSON.stringify(element, null, 2), "other : " + JSON.stringify(expectedResponse[index], null, 2))

        return true

    }

})

console.log(output)

pm.test("Body is correct", function () {

    pm.expect(output).to.be.empty

});

just store the expected values as array and then use is filter. This isfilter returns the unequal values, if there is no unequal values then returns empty array. so we are validating the returned output is empty

2 Likes

Thank you @praveendvd .
Let me try your solution, i will get back to you.

2 Likes

Hi @praveendvd
it returns TypeError: actualResponse.filter filter is not a function

filter is a method for array , make sure actualResponse is array

Yes it is in array but i stored in a variable.
inside the variable it is like:

[
{
“City”: “Paris”,
“Name”: “Bastille”
},
{
“City”: “Tokyo”,
“Name”: “Tomo”
},
{
“City”: “Santiago”,
“Name”: “H Brooks”
}
]

actualResponse = JSON.parse(pm.variables.get("variablename"))

in variable it might be stored as string first parse it to make it an array

1 Like

Correct, it works fine now, Thank you for your help.

1 Like

No issues :relaxed: welcome to the community :heavy_heart_exclamation: