首页 > 代码库 > [转]自己动手修改Robotium代码(上)
[转]自己动手修改Robotium代码(上)
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;
}
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);
}
{
asserter.assertViewShown(message, view, timeout);
}
public void assertViewShown(String message, View view, int timeout)
{
Assert.assertTrue(message, waiter.isViewShown(view, 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;
}
if(view == null)
return false;
long endTime = SystemClock.uptimeMillis() + timeout;
while (SystemClock.uptimeMillis() < endTime) {
if(view.isShown())
return true;
sleeper.sleep(MINISLEEP);
}
return false;
}
[转]自己动手修改Robotium代码(上)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。