自动化测试就是查找元素、操作元素,要查找元素,就需要根据元素的信息来查找(id、class、text、….)
定位元素的时候必须根据元素的相关特征来进行定位,而 UIAutomatorViewer 就是用来获取元素特征的。
一、启动
方法一:进入安装目录点击uiautomatorviewer.bat启动
方法二:在cmd终端中输入uiautomatorviewer启动。
小技巧:复制一个此文件,改名为u.bat。即可只输入u来启动。更方便!
![图片[1] - 使用UIAutomatorViewer 进行元素定位 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/12/2022092114093284.png)
![图片[2] - 使用UIAutomatorViewer 进行元素定位 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/12/2022092114104778.png)
二、截图App
1.启动模拟器,打开要测试的APP
![图片[3] - 使用UIAutomatorViewer 进行元素定位 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/12/2022092114214123.png)
2.启动uiautomatorviewer,会看到模拟器连接
![图片[4] - 使用UIAutomatorViewer 进行元素定位 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/12/2022092114211860.png)
3.点击截图app页面
![图片[5] - 使用UIAutomatorViewer 进行元素定位 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/12/2022092114240956.png)
三、获取元素
![图片[6] - 使用UIAutomatorViewer 进行元素定位 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/12/2022092114553489.png)
四、问题解决
问题一:UiAutomatorViewer闪退
通常是由于jdk版本不兼容导致,一般情况下使用jdk1.8
问题二:点击捕获界面元素信息报错
通常是因为UiAutomatorViewer连接不到模拟器/手机导致,只需要重置adb服务即可
- adb kill-server # 关闭adb服务
- adb start-server # 启动adb服务
问题三:romote object doesn’t exsit!
![图片[7] - 使用UIAutomatorViewer 进行元素定位 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/12/2022092114255682.png)
解决方法:网上还是有很多方法的,可能造成的原因不同,我是不断重启解决的 T T
- 在cmd命令窗口中输入 adb root 即可
- 重启手机无效
- 重新把手机拔了再插
- 重启appuim
- 重启uiautomatorviewer.bat
- 打开手机开发者权限,将USB调试按钮重新启动就好了
重点!!:一次不行,试多几次,这个工具不是太稳定哦
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END