2

I am trying to do a If Else condition on one of the scenarios that i encountered which requires the Match to be performed. Currently i have it handled via a Karate.call() with both the true and false condition and doing the matches there but it would be shorter for me to have it inline. I know that its not recommended to have conditional logic but this is an exception

**Current Implementation**
* def result = (response.status == 200) ? karate.call('listinPage.feature@FilterValidationPositive', {a: response, b:dbRows}) : karate.call('listinPage.feature@FilterValidationNegative', {a: response, b:dbRows})

**Desired**
Something along :
if (response.status == 200) match response.comment == 'xyz' else match response.comment == 'abc'
Jitendra Singh
  • 191
  • 1
  • 8

1 Answers1

1

You can use the eval keyword for multi-line JS blocks:

* def value = 'before'
* eval
"""
if (value == 'before') {
  value = 'after'
}
"""
* match value == 'after'

But please read this also: https://stackoverflow.com/a/50350442/143475

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