Is there an easier way to call a Java assertion from a Karate test and provide the assertion a failure message? I have a feeling there must be a more elegant way?
Here is how I am INCORRECTLY doing it now:
* def assertNotBlank =
"""
function(val, msg) {
var Assertions = Java.type('org.junit.jupiter.api.Assertions');
var StringUtils = Java.type('org.apache.commons.lang3.StringUtils');
var JSONObject = Java.type('org.json.JSONObject');
return Assertions.assertFalse(StringUtils.isBlank(
new org.json.JSONObject(val).toString()), msg);
}
"""
Then call it in your feature file like so:
And eval assertNotBlank {val: '#(response)', msg: 'The reason here.'}