1

I want to assert that the object array in the JSON response is ordered alphabetically based on one of the properties of the object (this is in ReadyAPI). I've tried this a number of ways but can't get it to work. This is what I've got:

json = new groovy.json.JsonSlurper().parseText(context.response)

assert json.data[0].foundPatientDisplayNaam.contains(context.expand('${Blaauw}'))

var lastItem = json.data.size()-1

assert json.data[lastItem].foundPatientDisplayNaam.contains(context.expand('${Ziende}'))

I've also tried solutions with ResponseAsXml#count(//*:foundPatientDisplayNaam, .last() and .length-1.

I suspect I'm missing some basic knowledge here but still, thanks in advance to anyone who's able to help me out here.

Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
  • While I'm curious as to what I'm doing wrong in the above, it occurred to me that a better solution would be asserting that the entire array is ordered alphabetically. I am not getting any further on that front either: https://stackoverflow.com/questions/74347598/groovy-assert-that-an-array-in-the-response-is-ordered-alphabetically – Philip Stuij Nov 07 '22 at 13:55

0 Answers0