monkey runner

/ 测试开发 / 0 条评论 / 721浏览
1. 参考blog
http://blog.sina.com.cn/s/blog_abb5fd6e0102vn8v.html jpython
http://www.amsoft.cn/post-290.html
http://blog.sina.com.cn/s/blog_7ce2cb4101016jl5.html
http://blog.csdn.net/vshuang/article/details/39783579

#杀掉待测程序,通常用于排除干扰
device.shell('am force-stop com.alpha.lenovo.launcher')
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
把设备和monkeyrunner绑定device=MonkeyRunner.waitForConnection(5,'手机名')

安装apk
device.installPackage(“xxx.apk”)
启动apk
device.startActivity(packageName/startActivity)
cmd下python的退出:exit();monkeyrunner的退出:ctrl+d

EasyMonkeyDevice
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice       
    from com.android.monkeyrunner.easy import EasyMonkeyDevice      
    from com.android.monkeyrunner.easy import By           
    device = MonkeyRunner.waitForConnection()     
    easy_device = EasyMonkeyDevice(device)      
    easy_device.startActivity(component='com.xuanwu.etion/.SplashActivity')     
    #输入用户名     
    device.type('mzba')          
    #触摸密码框,相当于获取焦点     
    easy_device.touch(By.id('id/login_edit_pwd'), MonkeyDevice.DOWN_AND_UP)      
    #输入密码    
    device.type('888888')    
    #按下返回键,相当于关闭输入法的弹出框    
    device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)         
    #easy_device.touch(By.id('id/login_edit_account'), MonkeyDevice.DOWN_AND_UP)        #点击登录按钮    
    easy_device.touch(By.id('id/login_btn'), MonkeyDevice.DOWN_AND_UP)  
运行脚本
1. 安装python2.7,在系统的环境变量Path上添加python的安装路径
2. 用adb连接测试设备
3. 进入android sdk的tools目录,执行monkeyrunner test.py