Reputation: 89
HI there I am making post call using karate And for that I am passing json Payload but before i pass it i want to validate is there any null or empty string present and if yes then Abort the post call and print message empty string or null values cant be accepted.
Thanks in advance!
peter thomas Thank you in advance
Upvotes: 1
Views: 235
Reputation: 58058
This doesn't make sense to me, because if you are preparing this payload yourself, you never need to validate it.
That said, you can run a match
anytime.
* def body = { myKey: 'myValue' }
* match body == { myKey: '#string' }
* url 'https://httpbin.org/anything'
* request body
* method post
* status 200
* match response contains deep { json: { myKey: 'myValue' } }
See how the second line does a validation.
Also refer this answer to see how you can programmatically run karate.match()
for advanced use-cases: https://stackoverflow.com/a/50350442/143475
Upvotes: 1