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;
}
}
}
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;
}
}
}
相关文章推荐
- android UiAutomator写一个等待元素出现并点击的方法
- android通过ksoap访问webservice方法传递一个复杂对象参数
- android uiautomator 一个截屏并且以当前时间命名图片名的方法
- C# 在两个不同的方法里面Lock同一个锁对象,是否需要线程等待?
- 写一个方法,参数接收一个String类型的对象,最终可以把这个字符串参数中出现过的每一个字母打印出来 例如: "wwqweqdasdafdsfdsferer" 将来方法接收这个参数后会打印:
- 关于FreeMarker获取一个对象中另一个对象出现的问题以及解决方法
- android uiautomator一个画心形图案的方法--代码的浪漫
- 【Android自学笔记】android真机测试时 出现 “远程主机强迫关闭了一个现有的连接”的解决方法
- android开发中在eclipse中导入一个项目时出现中文乱码的解决方法
- android中引用方法的时候,有时候要new一个对象才能引用,有时候直接.方法就可以了,为什么
- android UiAutomator一个验证修改姓名和随机设置性别的方法
- android UiAutomator自定义一个判断当前版本的方法
- android uiautomator如何写一个定时任务的方法
- android uiautomator如何写一个带参数的方法--以画圆为例
- Android开发过程中创建一个Message对象使用方法区别
- eclipse中导入android ADT-20.0.3出现的一个错误及解决方法
- 读取xml文件出现错误的一个解决方法(android)
- android UiAutomator一个在京东app里面自动签到领流量的方法
- Iterator 提供一种方法顺序访问一个对象中各个元素,而又不需要暴露该对象的内部表示
- 请教vs2005中单元测试时测试一个返回对象的方法应该怎么做?