本人之前写了等待对象出现的方法,今天突然发现,写得很烂,于是重写了一个等待对象出现的方法。分享出来,如有不足,还请指正。
public void waitForUiObject(String text) {//等待对象出现
Date start = new Date();
boolean key = true;
while(key){
sleep(200);
UiObject it = new UiObject(new UiSelector().text(text));
if (it.exists()) {
key = false;
}
Date end = new Date();
long time = end.getTime() - start.getTime();
if (time>10000) {
outputNotable("超过10秒没有出现!");
key = false;
}
}
}
还能换一种别的方法,把查找条件作为参数。
public void waitForUiObject(UiSelector selector) {//等待对象出现
Date start = new Date();
boolean key = true;
while(key){
sleep(200);
UiObject it = new UiObject(selector);
if (it.exists()) {
key = false;
}
Date end = new Date();
long time = end.getTime() - start.getTime();
if (time>10000) {
outputNotable("超过10秒没有出现!");
key = false;
}
}
}