首页 > 技术文章 > python+appium实现android APP 自动化测试之控件定位一

caiyun777 2018-09-20 18:02 原文

上一步已经把环境搭建好了,先不要急着写脚本,测试APP之前首先要知道app上每一个控件的‘地址’,如何准确的定位到这个控件呢?

1、adb 连接

把手机连接上电脑,开启文件传输模式,开启开发者模式,发开USB调试。

在cmd命令输入adb devices,查看是否能找到手机设备,能找到说明手机连接到电脑没问题了。

 

在手机上打开要测试的APP, 输入  cmd中输入adb shell dumpsys window w | findstr \/ | findstr name=

查看app的'appActivity'

 

2、APP控件定位

在上一步android SDK中打开控件监控工具:

D:\android\sdk\tools\hierarchyviewer.bat  

如果出现以下报错需要先关闭appium:

Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist! Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!

 

 resource-id处就是数字8的id地址了

 

推荐阅读