admin管理员组文章数量:1587993
类介绍
-
UiDevices代表设备状态
-
是单例模式
-
UIDevices功能
- 获取设备信息:屏幕分辨率,旋转状态,亮屏或者灭屏等操作
- 操作:按键,坐标操作,滑动,拖动,唤醒,截图等
- 监听器
-
源码的介绍:
/**
* UiDevice provides access to state information about the device.
* You can also use this class to simulate user actions on the device,
* such as pressing the d-pad or pressing the Home and Menu buttons.
* @since API Level 16
*/
翻译下就是:
- uidevice提供对设备状态信息的访问。
- 您还可以使用这个类来模拟设备上的用户操作,
- 如按D-PAD或按Home和菜单按钮。
一堆的API,下面我们举几个例子
image.png
主要API
- 按键和KeyCode使用
- 获取坐标以及点击
- 拖动,滑动
- 旋转屏幕
- 灭屏,唤醒
- 截图,等待
- 获取包名,开启通知栏,快速设置,获取布局文件
如何获取UiDevices
1. static UIDevice getInstance()
2. static UIDevice getInstance(Instrumentation instrumentation)
我们主要是使用功能第二个:
Instrumentation mInstrumentation=InstrumentationRegistry.getInstrumentation();
UIDevice mDevice=UiDevice.getInstance(mInstrumentation);
按键和KeyCode
目前的机器都是智能机,没有KeyCode了
手机常用的按键
- home
- menu
- back
- volume_up
- volume_down
- recentApps
- power
- dpad
- ......
API说明
返回值 | 方法名 | 描述 |
---|---|---|
boolean | pressBack() | 手机中的back按键 |
boolean | pressDpadCenter() | 轨迹球中点按键 |
boolean | pressDpadDown() | 轨迹球向下按键 |
boolean | pressDpadLeft() | 轨迹球向左按键 |
boolean | pressDpadRight() | 轨迹球向右按键 |
boolean | pressDpadUp() | 轨迹球向上按键 |
boolean | pressDelete() |
版权声明:本文标题:Java+Uiautomator自动化测试 -- 8.UiDevice学习(按键,坐标操作,滑动,拖动,唤醒,截图,亮屏,灭屏等) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1728024687a1142565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论