1

I tried couple of ways to make use of IF-Else conditional logic as mentioned in these two links

1 How to check additional values with if condition (using karate framework)?

[2]https://github.com/intuit/karate#conditional-logic

After trying different combinations I am still unsuccessful and I don't see other ways to make my scenario work. For better visibility and understanding I have attached screenshot.

conditional logic issue in karate

As shown both output2.c.data and z.d.data are empty array's. Using these two references I have defined
*def output4 = (z.d.data == output2.c.data ? {pass:true} : {pass:false})

I was expecting my output - output4- to be {"pass":true}

For unknown reasons my scenario is giving me the opposite of what I am expecting.

MKod
  • 803
  • 5
  • 20
  • 33

1 Answers1

3

You can't do an equals operation on two arrays in JavaScript, which is why Karate's "deep equals" match is needed.

* def foo = { data: [] } 
* def bar = { data: [] }

# wrong
* def result = foo.data == bar.data ? { pass: true } : { pass: false }
* match result == { pass: false }

# right
* def result = karate.match(foo.data, bar.data).pass ? { pass: true } : { pass: false }
* match result == { pass: true }

EDIT - this is a more detailed answer: https://stackoverflow.com/a/50350442/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248