4

I want to execute more than 1 statements provided an If condition is true. I want to know whether and how is it achievable in Intuit Karate framework.

In the Karate documentation, I find examples like below all of which have only one statement to be executed if the If condition is satisfied as listed below.

if (env == 'dev') karate.configure("ssl", true)

if (responseStatus == 200) karate.call('delete-user.feature')

if (responseStatus == 404) karate.abort()

I want to achieve something like below (only a pseudocode representation of my requirement and not as per the actual Karate syntax)

if (responseStatus ==200)

#statement 1

#statement 2

#statement 3

#end of If

Thanks!

Gautam Das
  • 41
  • 2

1 Answers1

0

Normally good tests should never do this. Make sure you read this also: https://stackoverflow.com/a/54126724/143475

But here are the 2 possible patterns:

a) use a second feature file:

* if (condition) karate.call('second.feature')

b) use a function, the disadvantage is only the JS API, things like match not supported

* def fun = 
"""
function() {
  // line 1
  // line 2
}
"""
* if (condition) fun()
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • @GautamDas I'm not really interested in the details, I think my answer gives you all the information you need. if there is any specific thing you don't understand, ask a new question please – Peter Thomas Jun 25 '20 at 08:49