一. UiDevices类
UiDevices代表设备状态。测试时用于检查设备不同属性的状态
private static Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
public static UiDevice Device = UiDevice.getInstance(instrumentation);
|方法名 | 描述 | 使用
|PressHome() | 按home键 | Device.PressHome()
|PressBack() | 按返回键 | Device.PressBack()
|PressMenu() | 按菜单键 | Device.PressMenu()
|getDisplayHeight() | 获取屏幕高度 | Device.getDisplayHeight()
| getDisplayWidth() | 获取屏幕宽度 | Device.getDisplayWidth()
| getDisplayRotation() | 获取屏幕旋转角度 | Device.getDisplayRotation()
| isScreenOn() | 判断屏幕是否是亮的 | Device.isScreenOn()
| sleep() | 熄屏 | Device.sleep()
| wakeUp() | 点亮屏幕 | Device.wakeUp()
| takeScreenshot(path) | 截图 | Device.takeScreenshot(new fie (path))
| openNotification() | 打开通知栏 | Device.openNotification()
| getCurrentPackckageName() | 获取当前界面的包名 | Device.getCurrentPackckageName()
| click() | 点击 | Device.click(x,y)
| swipe() | 滑动 | Device.swipe(x1,y1,x2,y2,step)
| drag() | 拖拽 | Device.drag(x1,y1,x2,y2,step)