Robotium做爲Android自動化測試框架,還有許多不完善的地方,也不能知足測試人員的全部要求。那麼,本文以四個實際中碰到的問題爲例,介紹改動Robotium源碼的過程。框架
public boolean waitForActivity(String name, int timeout){
Activity currentActivity = activityUtils.getCurrentActivity(false);
final long endTime = SystemClock.uptimeMillis() + timeout;
while(SystemClock.uptimeMillis() < endTime){
if(currentActivity != null && currentActivity.getClass().getSimpleName().equals(name)) {
return true;
}
sleeper.sleep(MINISLEEP);
currentActivity = activityUtils.getCurrentActivity(false);
}
return false;
}
currentActivity.getClass().getSimpleName().equals(name)。因而,我把getSimpleName()改成getName(),這樣之後使用solo.waitForActivity函數時,傳入Activity的全名就好。
public void assertViewShown(String message, View view, int timeout)
{
asserter.assertViewShown(message, view, timeout);
}
public void assertViewShown(String message, View view, int timeout)
{
Assert.assertTrue(message, waiter.isViewShown(view, timeout));
}
public boolean isViewShown(View view, int timeout){
if(view == null)
return false;
long endTime = SystemClock.uptimeMillis() + timeout;
while (SystemClock.uptimeMillis() < endTime) {
if(view.isShown())
return true;
sleeper.sleep(MINISLEEP);
}
return false;
}