Hi,
Below is the JSON request and response and I am using version 5.1.2. and the resolution provided by you for counting cancellation policy "def Cancellationpolicy = context.expand( '${BlockRoomFixedBE#ResponseAsXml#count(//*:BlockRoomResult/*:HotelRoomsDetails[0]/*:CancellationPolicies)}' )" is not working it is giving me count 0 and on the same time I am using count assertion its giving me count 8. |
I did not give you that solution, it was posted by Siking. The solution I gave was for you to use the JSONPath Count assertion. Since you would rather use Groovy to get the count then you should parse the JSON with JsonSlurper, example below.
import groovy.json.JsonSlurper
def response = context.expand( '${BlockRoomFixedBE#Response}')
def slurper = new JsonSlurper()
def result = slurper.parseText(response)
def policyCount = 0
for(hrd in result.BookResult.HotelRoomDetails)
{
policyCount = policyCount + hrd.CancellationPolicies.length
}
log.info policyCount
Regards,
Marcus
SmartBear Support