实现原理

Hierarchy Viewer:获得当前手机实时的UI信息,方便用于手机的自动化测试;

python中的subprocess.Popen():调用系统命令;

uiautomator工具:获取界面控件信息;

adb命令:对手机进行操作;

 

测试环境

1、HierarchyViewer将把下一台Android设备的4939端口映射到PC的4939端口

adb devices  查看手机设备号

adb -s 手机设备号 forward tcp:4939 tcp:4939

2、判断手机是否开启了view server,如果没开启则开启

adb -s 手机设备号 shell service call window 3  

通过返回值查看

"Result: Parcel(00000000 00000000 '........')  --没开

"Result: Parcel(00000000 00000001 '........')  --开启

开启view server

adb -s 手机设备号 shell service call window 1 i32 4939

关闭 view server

adb -s 手机设备号 shell service call window 2 i32 4939

说明:只有模拟器或者root手机才可以开启view service,实际操作过程中发现root手机开启view service 并非命令可完成,故先行使用模拟器进行测试

3、关键adb命令

adb shell uiautomator dump /mnt/sdcard/window_dump.xml  获得手机当前界面的UI信息,生成window_dump.xml

adb shell input keyevent  21  模拟键盘操作

adb shell input text “123”  输入text

......

 

posted on 2016-09-06 16:25  laclt  阅读(12502)  评论(0编辑  收藏  举报