UiAutoMator一些常用的方法
2016-02-24 16:37
489 查看
常用查找UiObject方法
// 通过ID查找
public static UiObject findById(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text));
return appBtn;
}
例如:UiObject search_src_text =findById("com.android.contacts:id/search_view")
// 通过resource和description查找
public static UiObject findByResourceIdAndDesc(String className, String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(className)
.description(text));
return appBtn;
}
例如:UiObject back_camera = findByResourceIdAndDesc(
"com.android.camera2:id/camera_toggle_button","Play video");
// 按Text Contains定位
public static UiObject findByTextContains(String text) {
UiObject getItem = new UiObject(new UiSelector().textContains(text));
return getItem;
}
例如:UiObject notice = findByTextContains("Remember photo locations");
// 通过resource和index查找
public static UiObject findByResourceIdAndIndex(String className, int index)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(className)
.index(index));
return appBtn;
}
例如:UiObject back_camera = findByResourceIdAndIndex(
"com.android.camera2:id/camera_toggle_button",0);
// 通过ID,instance查找
public static UiObject findByIdInStance(String text, int index)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text)
.instance(index));
return appBtn;
}
例如:UiObject back_camera = findByIdInStance(
"com.android.camera2:id/camera_toggle_button",1);
// 按照className查找UiScrollable;
public static UiScrollable findUiScrollableByClassName(String className)
throws UiObjectNotFoundException {
UiScrollable scrItem = new UiScrollable(
new UiSelector().className(className));
return scrItem;
}
// 通过source和text查找
public static UiObject findByResourceIdAndText(String text1, String text2)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text1).text(
text2));
return appBtn;
}
例如:UiObject mode = findByResourceIdAndText(
"com.android.camera2:id/selector_text", "text");
// 通过source和text查找
public static UiObject findByResourceIdAndTextContains(String resourceId, String textContains)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(resourceId).textContains(
textContains));
return appBtn;
}
例如:UiObject mode = findByResourceIdAndTextContains(
"com.android.camera2:id/selector_text", "text");
// 按照className和index在UiScrollable中查找
public static UiScrollable findUiScrollableByClassNameAndInstance(
UiScrollable uiScrollable, String className, int index)
throws UiObjectNotFoundException {
UiScrollable scrItem = new UiScrollable(new UiSelector().className(
className).instance(index));
return scrItem;
}
// 获取UiCollection中的子对象的个数
public static int findChildCountFromUiCollectionByClassName(
UiCollection uiCollection, String className)
throws UiObjectNotFoundException {
return uiCollection
.getChildCount(new UiSelector().className(className));
}
// 在UiScrollable中通过className和instance查找
public static UiObject findFromUiScrollableByClassNameAndInstance(
UiScrollable uiScrollable, String className, int index)
throws UiObjectNotFoundException {
return uiScrollable.getChild(new UiSelector().className(className)
.index(index));
}
// 按className定位Scrollable
public static UiScrollable findScrollableByClass(String className) {
return new UiScrollable(new UiSelector().className(className));
}
// 按resource定位Scrollable
public static UiScrollable findScrollableByResource(String text) {
return new UiScrollable(new UiSelector().resourceId(text));
}
// 从UiScrollable得到子对象,通过className和instance
public static UiObject findChildFromUiScrollableByClassNameAndInstance(
UiScrollable scrollable, String className, int instance)
throws UiObjectNotFoundException {
return scrollable.getChild(new UiSelector().className(className)
.instance(instance));
}
// 从UiScrollable得到子对象,通过TEXT
public static UiObject findChildFromUiScrollableByText(
UiScrollable scrollable, String text)
throws UiObjectNotFoundException {
return scrollable.getChild(new UiSelector().text(text));
}
// 获得collection对象中的子元素个数,以className作为筛选标准
public static int findChildCountFromCollection(UiCollection collection,
String className) {
return collection.getChildCount(new UiSelector().className(className));
}
// 在UiScrollable中通过className查找
public static UiObject findFromUiScrollableByClassName(
UiScrollable uiScrollable, String className)
throws UiObjectNotFoundException {
return uiScrollable.getChild(new UiSelector().className(className));
}
// 通过resource查找UiCollection
public static UiCollection findUicollectionByResource(String text)
throws UiObjectNotFoundException {
UiCollection uiCollection = new UiCollection(
new UiSelector().resourceId(text));
return uiCollection;
}
// 通过test查找
public static UiObject findByText(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().text(text));
return appBtn;
}
// 通过package查找
public static UiObject findByPackage(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().packageName(text));
return appBtn;
}
// 通过description查找
public static UiObject findByDesc(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().description(text));
return appBtn;
}
// 通过className查找
public static UiObject findByClassName(String className)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().className(className));
return appBtn;
}
// 通过descrice和index查找
public static UiObject findByDescContInstance(String text, int index)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().descriptionContains(
text).instance(index));
return appBtn;
}
// 通过ID查找
public static UiObject findById(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text));
return appBtn;
}
例如:UiObject search_src_text =findById("com.android.contacts:id/search_view")
// 通过resource和description查找
public static UiObject findByResourceIdAndDesc(String className, String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(className)
.description(text));
return appBtn;
}
例如:UiObject back_camera = findByResourceIdAndDesc(
"com.android.camera2:id/camera_toggle_button","Play video");
// 按Text Contains定位
public static UiObject findByTextContains(String text) {
UiObject getItem = new UiObject(new UiSelector().textContains(text));
return getItem;
}
例如:UiObject notice = findByTextContains("Remember photo locations");
// 通过resource和index查找
public static UiObject findByResourceIdAndIndex(String className, int index)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(className)
.index(index));
return appBtn;
}
例如:UiObject back_camera = findByResourceIdAndIndex(
"com.android.camera2:id/camera_toggle_button",0);
// 通过ID,instance查找
public static UiObject findByIdInStance(String text, int index)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text)
.instance(index));
return appBtn;
}
例如:UiObject back_camera = findByIdInStance(
"com.android.camera2:id/camera_toggle_button",1);
// 按照className查找UiScrollable;
public static UiScrollable findUiScrollableByClassName(String className)
throws UiObjectNotFoundException {
UiScrollable scrItem = new UiScrollable(
new UiSelector().className(className));
return scrItem;
}
// 通过source和text查找
public static UiObject findByResourceIdAndText(String text1, String text2)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text1).text(
text2));
return appBtn;
}
例如:UiObject mode = findByResourceIdAndText(
"com.android.camera2:id/selector_text", "text");
// 通过source和text查找
public static UiObject findByResourceIdAndTextContains(String resourceId, String textContains)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(resourceId).textContains(
textContains));
return appBtn;
}
例如:UiObject mode = findByResourceIdAndTextContains(
"com.android.camera2:id/selector_text", "text");
// 按照className和index在UiScrollable中查找
public static UiScrollable findUiScrollableByClassNameAndInstance(
UiScrollable uiScrollable, String className, int index)
throws UiObjectNotFoundException {
UiScrollable scrItem = new UiScrollable(new UiSelector().className(
className).instance(index));
return scrItem;
}
// 获取UiCollection中的子对象的个数
public static int findChildCountFromUiCollectionByClassName(
UiCollection uiCollection, String className)
throws UiObjectNotFoundException {
return uiCollection
.getChildCount(new UiSelector().className(className));
}
// 在UiScrollable中通过className和instance查找
public static UiObject findFromUiScrollableByClassNameAndInstance(
UiScrollable uiScrollable, String className, int index)
throws UiObjectNotFoundException {
return uiScrollable.getChild(new UiSelector().className(className)
.index(index));
}
// 按className定位Scrollable
public static UiScrollable findScrollableByClass(String className) {
return new UiScrollable(new UiSelector().className(className));
}
// 按resource定位Scrollable
public static UiScrollable findScrollableByResource(String text) {
return new UiScrollable(new UiSelector().resourceId(text));
}
// 从UiScrollable得到子对象,通过className和instance
public static UiObject findChildFromUiScrollableByClassNameAndInstance(
UiScrollable scrollable, String className, int instance)
throws UiObjectNotFoundException {
return scrollable.getChild(new UiSelector().className(className)
.instance(instance));
}
// 从UiScrollable得到子对象,通过TEXT
public static UiObject findChildFromUiScrollableByText(
UiScrollable scrollable, String text)
throws UiObjectNotFoundException {
return scrollable.getChild(new UiSelector().text(text));
}
// 获得collection对象中的子元素个数,以className作为筛选标准
public static int findChildCountFromCollection(UiCollection collection,
String className) {
return collection.getChildCount(new UiSelector().className(className));
}
// 在UiScrollable中通过className查找
public static UiObject findFromUiScrollableByClassName(
UiScrollable uiScrollable, String className)
throws UiObjectNotFoundException {
return uiScrollable.getChild(new UiSelector().className(className));
}
// 通过resource查找UiCollection
public static UiCollection findUicollectionByResource(String text)
throws UiObjectNotFoundException {
UiCollection uiCollection = new UiCollection(
new UiSelector().resourceId(text));
return uiCollection;
}
// 通过test查找
public static UiObject findByText(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().text(text));
return appBtn;
}
// 通过package查找
public static UiObject findByPackage(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().packageName(text));
return appBtn;
}
// 通过description查找
public static UiObject findByDesc(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().description(text));
return appBtn;
}
// 通过className查找
public static UiObject findByClassName(String className)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().className(className));
return appBtn;
}
// 通过descrice和index查找
public static UiObject findByDescContInstance(String text, int index)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().descriptionContains(
text).instance(index));
return appBtn;
}
相关文章推荐
- 老李分享:接电话扩展之uiautomator
- 老李分享:接电话之uiautomator
- Effective Android UI - MVP
- Your build settings specify a provisioning profile with the UUID “”, however...
- Yum中实现与apt-get install build-essential功能类似的命令
- 给UIColloectionViewCell设置点击效果,解决点击效果错位的问题
- Android Volley完全解析(三),定制自己的Request
- [转]C#子线程更新UI控件的方法实例总结
- 将UIScrollView点击点击事件传递到父View
- Fuel SSH访问控制节点的方法
- 怎样可以sign GVS的build
- Animation动画详解(六)——ValueAnimator高级进阶(二)
- UISearchController的基本使用
- ubuntu error: SSL modules require the OpenSSL library.
- UITabBarController--选项卡栏控制器
- 为何Math.abs(Integer.MIN_VALUE) = Integer.MIN_VALUE
- UITextField限制输入长度
- iOS 3D UI(3D翻转)
- 通过xib加载UITableViewCell的新方式
- 为Openstack创建实例(对fuel原生部分的修订)