UI Automator

1.UI Automator

UI自动化测试框架,安卓移动端app

要求:Android4.3以上

1) 提供一系列API:执行UI测试在系统或者第三方app上面

2) 允许在被测设备上执行操作,比如打开系统设置菜单

3) 适合编写黑盒自动化测试

2.UI Automator框架的主要特点

1) 元素定位:UI Automtor Viewer 扫描、分析待测应用的UI组件的图像工具

2) 元素操作:Accessing device state 在目标设备和app上的各种操作。

3) 元素识别:UI Automator APIs 在多个应用程序中捕获和操作UI组件

3.UI Automtor Viewer 元素定位

android8.1以后sdk tools自带的uiautomator直接打开,截取不到机器界面信息。

可以使用以下方法手动截取。

首先操作机器定位到要分析的界面。

1.截取uix资源文件

adb shell uiautomator dump /sdcard/screen.uix

adb pull /sdcard/screen.uix D:/screen.uix

2.截取截图

adb shell screencap -p /sdcard/screen.png

adb pull /sdcard/screen.png D:/screen.png

打开sdk tools目录下的uiautomatorviewer.bat,导入从机器获取的截图和资源文件

*可以搞一个bat脚本

3.uiautomatorviewer升级工具

将所有jar包拷贝到%SDK%/tools\lib目录下,覆盖原来的uiautomatorviewer.jar

 

 

4.app页面元素定位

1)通过id定位元素:resrouce-id

2)通过ClassName定位:classname

3)通过Accessibilityld定位:content-desc

4)通过AndroidUiAutomator定位

5)通过xpath定位

尽量不用xpath,AndroidUiAutomator效率最高

 

posted @ 2021-12-15 10:44  DaBenYing  阅读(271)  评论(0编辑  收藏  举报