Siva
Siva

Reputation: 123

Assert # of values in an Array

This is my response array.

"IDValues": [
    {
      "Id": 1,
    },
    {
      "Id": 2,
    },
    {
      "Id": 3,
    },
    {
      "Id": 4,
    },
    {
      "Id": 5,
    },
]

I have used JSON Extractor and Debug Sampler to find the count of Id's in the array. Got the answer as 5.

Now I have to assert the count value as 5. To keep it as a validation point.

I have tried using XPath extractor and Regular Expression Extractor, but all I was able to do is to extract the value but not assert it. How can this be accomplished? Which post processor should be used ?

Upvotes: 0

Views: 174

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

  1. Add JSON Extractor as a child of the request which returns the above JSON and configure it as follows:

    enter image description here

  2. It will produce the following JMeter Variables:

    IDValues_1={"Id":1}
    IDValues_2={"Id":2}
    IDValues_3={"Id":3}
    IDValues_4={"Id":4}
    IDValues_5={"Id":5}
    IDValues_matchNr=5
    
  3. Now you can use Response Assertion to verify if IDValues_matchNr variable value is equal to 5, the relevant configuration would be

    enter image description here

Upvotes: 1

Related Questions