karatekarate-call-single

How to write switch statement in Karate Framework


How to add switch statement in feature file?

I need to verify around 20 web tables data with database. for this I'm writing one common scenario which will work for all the web tables based on the condition.

Is there any possible like below in karate framework - Scenario level

switch(expression){  
case table1:  
  //code to be executed;
  break;  
case table2:  
  //code to be executed;  
  break;  //optional

case table3:  
  //code to be executed;  
  break;  //optional
......

default:  
  //code to be executed if all cases are not matched;  
}

Solution

  • Karate is not designed for this. Maybe this part should be written in JS code or Java code which you can mix into a test.

    That said, I'm pretty sure with some creativity you can use this approach: https://stackoverflow.com/a/59162760/143475

    Also refer: https://stackoverflow.com/a/50350442/143475