您的位置:首页 > 产品设计 > UI/UE

android UiAutomator写一个等待对象出现的方法

2017-02-28 15:41 351 查看
本人之前写了等待对象出现的方法,今天突然发现,写得很烂,于是重写了一个等待对象出现的方法。分享出来,如有不足,还请指正。

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;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐