If then else implementation to chose baseURL in Karate DSL

Here is a hint. JSON is actually a pretty useful data-structure (think hash-map or dictionary) and you can lookup a value without needing an if statement.

* def data =
"""
{
  qa: {
     sos: 'https://sos.qa.tceu.net',
     acn: 'https://acn.qa.tceu.net'  
  }  
}
"""
* def env = 'qa'
* def urls = data[env]
* def action = 'sos'
* def actionUrl = urls[action]
* match actionUrl == 'https://sos.qa.tceu.net'

This should get you on your way 🙂

EDIT – also see this: https://stackoverflow.com/a/67868935/143475

Leave a Comment