Forum Discussion

jsontester's avatar
jsontester
Occasional Contributor
4 years ago

Assertion for 1 specific value which contains in all results in response

After a GET request where I'm searching for a specific postal code, I get response with 75 results. I want to assert that all 70 results have the same value for property(postalCode). If I use the...
  • nmrao's avatar
    4 years ago

    Strange. Not sure why problem with 70 results?

     

    Would it be possible to share the screenshot of the assertion with expression and expected result?

     

    Are you OK to use below one-liner script assertion?

     

    #Checks every postalCode is 1520

     

     

    assert (new groovy.json.JsonSlurper().parseText(context.response).data.postalCode.every{it == 1520})

     

     

    or

    #Data other than postalCode 1520 is zero

     

     

    assert new groovy.json.JsonSlurper().parseText(context.response).data.postalCode.findAll {it != 1520 }.size() == 0

     

     

    or even this

     

    assert !(new groovy.json.JsonSlurper().parseText(context.response).data.postalCode.findAll {it != 1520 })

     

     

  • nmrao's avatar
    nmrao
    4 years ago

    Verifying city name for all the values is "New York", you can do in the same way as previous assertion i.e., check all the values are equal to mentioned values.

     

    You can add another assertion for the test step

    assert (new groovy.json.JsonSlurper().parseText(context.response).data.City.every{it == "New York"})