Uiautomator API简介-摘要
2016-01-12 10:02
561 查看
本文适合初学者
uiautomator API在 uiautomator.jar 文件中
1.UiDevice
UiDevice代表设备状态。在测试中,可以通过UiDevice实例主要进行以下两个方面的操作:
1.检测设备的各种属性
e.g.:例如当前的屏幕方向以及屏幕尺寸a)getUiDevice().getDisplayRotation()
b)getUiDevice().getDisplayHeight()
2.通过UiDevice实例来执行设备级别的操作
e.g.:例如 把设备设置为横屏或者竖屏、按下Home按键a)getUiDevice().pressHome()
b)getUiDevice().pressMenu()
c)getUiDevice().pressBack()
2.UiSelector
UiSelector代表一种搜索条件,可以在当前界面上查询和获取特定元素的句柄,当找到多余一个的匹配元素,则返回布局层次结构上第一个匹配元素作为目标UiObject,当构造一个UiSelector对象时,可以使用链式调用多个属性来缩小查询范围
例如:“`
package com.uiselectortest;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class Demo extends UiAutomatorTestCase {
/**
* @param args
*/
public static void main(String[] args) {
String jarName, testClass, testName, androidId; jarName="demo"; testClass="com.testuiselector.Demo"; testName="testDemo"; androidId="1"; new UiAutomatorHelper(jarName, testClass, testName, androidId); } public void testDemo() throws UiObjectNotFoundException{ UiSelector l=new UiSelector().text("People"); UiObject p=new UiObject(l); p.click(); }
}
“`
各个属性详细介绍
点我哈常见Android组件属性
未完-待续
相关文章推荐
- ios推送:本地通知UILocalNotification
- 1月12号 UIView
- hdoj5400Arithmetic Sequence【等差数列】
- IOS上 关于状态栏的相关设置(UIStatusBar)
- 运用Acronis True Image恢复系统
- android queryIntentActivities如何寻找出某个intent是否可用
- 解决UITableView设置了偏移量但是不偏移的问题
- Android studio 项目没有错误,运行按钮为灰色无法运行,rebuild 和 clean 都没有用
- NSOperationQueue
- 转 史上最完整交互设计基本原则
- easyui validatebox 验证类型
- 【代码笔记】点击任何处,显示出红色的UIView
- 【代码笔记】点击任何处,显示出红色的UIView
- RequireJS模块化加载
- 使用Fragment创建动态UI
- Implement Queue using Stacks
- 使用request简单爬虫
- UITabBarControllerDemo 一个最基本到标签控制器
- New UI-获取手机屏幕尺寸与分辨率,屏幕适配,横竖屏问题
- New UI-常用计量单位px,dp,sp,pt解析与转换