2017-07-31 131 views
0

您能幫我解決這個問題嗎?我正在撰寫濃縮咖啡測試。這裏是代碼:如何在濃縮咖啡測試中循環3個按鈕

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次。

在此先感謝!

回答

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); 
} 
+0

非常感謝,它的工作 – TLDima