问题
JSON Response: [ { "actNum": "12345678", "prodType": "Test", "period": { "January": [ { "name": "Jake", "rRar": 12.34, "lRar": 340.45, "address": "New York" }, { "name": "Jorge", "rRar": 28.78, "lRar": 250.49, "address": "Chicago" } ] } } ]
I have to verify that numeric fields in the above response rRar and lRar should have value till two decimal points like 12.78,32.56.
Could anyone please help me if this validation can be done using Karate API?
回答1:
Here you go:
* def nums = $response..rRar
* def temp = $response..lRar
* karate.appendTo(nums, temp)
* def strs = karate.map(nums, function(x){ return x + '' })
* match each strs == '#regex [0-9].+\\.[0-9]{2}'
来源:https://stackoverflow.com/questions/61880641/verify-numeric-fields-in-json-response-have-values-till-two-decimal-points-using