The goal is to do soft assertion on each JSON field.
* def KAFKA_TOPIC = "topic1"
* def kafkaExpected = {field1:"value1",field2:"value2",field3:"value3"}
* def kafkaActual = {"topic1":[{field1:"value1",field2:"x",field3:"y"}]}
* configure continueOnStepFailure = { enabled: true, continueAfter: false, keywords: ['match'] }
* match (kafkaActual[KAFKA_TOPIC]) == ['#(kafkaExpected)'] <-- do we have one-liner like this to do soft assertions on all fields?
* configure continueOnStepFailure = false
Output:
$[0].field2 | not equal (STRING:STRING)
'x'
'value2'
Instead of doing it 1 by 1.
* match (kafkaActual[KAFKA_TOPIC])[0].field1 == kafkaExpected.field1
* match (kafkaActual[KAFKA_TOPIC])[0].field2 == kafkaExpected.field2
* match (kafkaActual[KAFKA_TOPIC])[0].field3 == kafkaExpected.field3
Output:
match failed: EQUALS
$ | not equal (STRING:STRING)
'x'
'value2'
match failed: EQUALS
$ | not equal (STRING:STRING)
'y'
'value3'
And whats weird is that on terminal logs it only printed one assertion, either on both approach.
$ | not equal (STRING:STRING)
'y'
'value3'
Trying to use Karate.forEach but seems like not the right path.