1

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;  
}
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thanks for quick response Peter..! Can we write if else condition for all the 20 tables?. My problem is, most of the validations are common for all the tables, but few validations are specific to tables.In that case how can use in middle of scenario js or Java functio – KrishnaKotha Jan 31 '23 at 19:25
  • @KrishnaKotha you choose the best way from the second link above. maybe you just need to call a separate feature file which has the specific validations. you can use a variable to drive the file name that is called – Peter Thomas Feb 01 '23 at 02:56