Verify numeric fields in JSON response have values till two decimal points using Karate

孤者浪人 提交于 2021-01-28 18:05:01

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!