如何在浓缩咖啡测试中循环3个按钮

时间:2017-07-31 08:51:45

标签: android android-espresso

你能帮我解决这个问题吗?我正在写一个浓咖啡测试。这是代码:

 onView(ViewMatchers.withId(R.id.btnControl1)).perform(click());
 SystemClock.sleep(delay);
 onView(ViewMatchers.withId(R.id.btnControl2)).perform(click());
 SystemClock.sleep(delay);
 onView(ViewMatchers.withId(R.id.btnControl3)).perform(click());
 SystemClock.sleep(delay);

我想循环它。例如:单击这3个按钮20次。

提前致谢!

1 个答案:

答案 0 :(得分:2)

你可以把它放在for循环中:

for (int i = 0; i < 20; i++) {
    onView(ViewMatchers.withId(R.id.btnControl1)).perform(click());
    SystemClock.sleep(delay);
    onView(ViewMatchers.withId(R.id.btnControl2)).perform(click());
    SystemClock.sleep(delay);
    onView(ViewMatchers.withId(R.id.btnControl3)).perform(click());
    SystemClock.sleep(delay);
}