3

Find the example here.

def a = condition ? " karate match statement " : "karate match statement"

Is it possible to do something like this??

MrLeeh
  • 4,895
  • 3
  • 29
  • 46
test-profile
  • 43
  • 1
  • 1
  • 6

1 Answers1

3

This is not recommended practice for tests because tests should be deterministic.

The right thing to do is:

That said, if you really insist on doing this in the same flow, Karate allows you to do a match via JS in 0.9.6.RC4 onwards.

See this thread for details: https://github.com/intuit/karate/issues/1202#issuecomment-653632397

enter image description here

The result of karate.match() will return a JSON in the form { pass: '#boolean', message: '#string' }

If none of the above options work - that means you are doing something really complicated, so write Java interop / code to handle this

Peter Thomas
  • 47,282
  • 14
  • 68
  • 196
  • 2
    I want to check for a key name in some JSON and then do assertion only if the key is present in json, for which I want to use _match_ statement. So I want to use this kind of conditional statement. I will make use of above example by having updated version of karate. Thank you. – test-profile May 15 '18 at 14:55
  • * if (response != [] || '') karate.call('/features/PASE/helper/ServiceAddressessHelper.feature@BaseScenarioServiceAddressess5') This is ServiceAddressessHelper.feature file Feature: Helper Feature @BaseScenarioServiceAddressess5 Scenario: Helper scenario * match each response == expectedResponseServiceAddressess This is not working. I am not able to figure it out. How to pass 'response' from test feature file – Virender Kamboj Jul 24 '21 at 19:44
  • @VirenderKamboj follow this process please: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Jul 25 '21 at 03:01