-1

I know this is weird, I want do this way and I couldn't find a solution which is why asking you guys! I've methods like which I'm calling inside a class as listed below - //

     @Test
     Key.chooseNew(0);
     Key.navigate_toNew(1);
     Key.send_keys_loginNew(2);
     Key.logoutNew(3);

How can I run it in a loop in java replacing those numbers or such things doesn't exist?!

Abhinav
  • 31
  • 3

2 Answers2

3

You are calling a different method on each line so there is no loop.

The only pattern I can see is:

int i = 0;
Key.chooseNew(i++);
Key.navigate_toNew(i++);
Key.send_keys_loginNew(i++);
Key.logoutNew(i++);
Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
0

Have a look at Reflection in java. You could save the names of the methods to be called in a list in the order you want them called and then inside the loop you can call the method with the method name using obj.getClass().getMethod() as shown in this post.

Hope this is what you were looking for.

Community
  • 1
  • 1
anirudh
  • 4,116
  • 2
  • 20
  • 35