欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android自动测试工具Monkey的实现方法

程序员文章站 2024-03-03 22:18:46
1. android monkey 实现操作流程: 准备:在eclipse里安装phyon插件,可以选择在线安装,也可以下载zip解压后放在eclipse安装目录的dro...

1. android monkey 实现操作流程:

准备:在eclipse里安装phyon插件,可以选择在线安装,也可以下载zip解压后放在eclipse安装目录的dropins下,如 : /personal/software/android_developtools/adt-bundle-mac-x86_64-20130522/eclipse/dropins/pydev 2.8.2

插件准备就绪就重启eclipse,检验pydev是否正常工作,然后开始monkeyrunner测试:

第一步:

gufeitekimacbook-pro:~ gufei$ cd /personal/software/android_developtools/adt-bundle-mac-x86_64-20130522/sdk/tools

第二步:

gufeitekimacbook-pro:tools gufei$ ls
jetemulator-x86monkeyrunner
notice.txtemulator64-armproguard
adb_has_moved.txtemulator64-mipssource.properties
androidemulator64-x86sqlite3
antetc1toolsupport
appshierarchyviewersystrace
ddmshprof-convtemplates
dmtracedumpjobbtraceview
draw9patchlibuiautomatorviewer
emulatorlintzipalign
emulator-armmksdcard
emulator-mipsmonitor

第三步:

gufeitekimacbook-pro:tools gufei$ ./emulator -avd android_480_800
emulator: emulator window was out of view and was recentered

然后重新打开一个新的命令窗口

第四步:

gufeitekimacbook-pro:~ gufei$ cd /personal/software/android_developtools/adt-bundle-mac-x86_64-20130522/sdk/tools
gufeitekimacbook-pro:tools gufei$ ./monkeyrunner
jython 2.5.3 (2.5:c56500f08d34+, aug 13 2012, 14:54:35)
[java hotspot(tm) 64-bit server vm (apple inc.)] on java1.6.0_51

 第五步:

from com.android.monkeyrunner import monkeyrunner,monkeydevice,monkeyimage

 第六步:

android_480_800.installpackage("/personal/developer/android/project/unionpay/android/upclient_3_0_lib/bin/upclient_3_0_lib.apk")

ps:里面的5指等待5s,可以不写,代表永远等待,也可以自己自定义时间。

 第七步:

android_480_800.installpackage("/personal/developer/android/project/unionpay/android/upclient_3_0_lib/bin/upclient_3_0_lib.apk")

安装成功后命令窗口打印出:true

 第八步:

 

android_480_800.startactivity(component="com.unionpay/com.unionpay.client3.upactivitywelcome")

 观察模拟器是否已经打开该界面

 第九步:(自己模拟点击坐标)

 

android_480_800.touch(386.0,399.0,android_480_800.down_and_up)
android_480_800.touch(35.0,146.0,android_480_800.down_and_up)
android_480_800.touch(5.0,609.0,android_480_800.down_and_up)
android_480_800.touch(44.0,569.0,android_480_800.down_and_up)
android_480_800.touch(-1.0,-1.0,android_480_800.down_and_up)
android_480_800.touch(467.0,759.0,android_480_800.down_and_up)
android_480_800.touch(457.0,726.0,android_480_800.down_and_up)
android_480_800.touch(265.0,776.0,android_480_800.down_and_up)
android_480_800.touch(271.0,787.0,android_480_800.down_and_up)
android_480_800.touch(176.0,278.0,android_480_800.down_and_up)
android_480_800.touch(187.0,257.0,android_480_800.down_and_up)
result= android_480_800.takesnapshot() 
result.writetofile("/users/gufei/downloads/monkeyrunnershoot.png") 
print("ok!")