A few days ago with colleagues to study the basic use of the next Monkeyrunner, the following with a simple Monkeyrunner examples and share with you (basic operation, the gods can float through ~), The program installs a Android App Package (take an example of a search), and do some simple actions ~ ~ If there are errors welcome to correct
# Modules required to import this program
From Com.android.monkeyrunner import Monkeyrunner, monkeydevice,monkeyimage
From Com.android.monkeyrunner.easy import Easymonkeydevice
From Com.android.monkeyrunner.easy Import by
# connect the current device and return a monkeydevice object
Device =monkeyrunner.waitforconnection ()
Easy_device=easymonkeydevice (device)
# Install the Android package, note that the return value returned by this method is Boolean, so you can determine whether the installation process is normal, the bar right oblique
Device.installpackage (' e:/android/ssj_ad20140808v1.0.1.apk ')
# Run an activity in this app. Note: The app name can be viewed in eclipse
Device.startactivity (component= ' com.sinoglobal.searchingforfood/.activity. Splashactivity ')
# Click Personal Center (click through the control ID)
Easy_device.touch (by.id (' id/iv0 '), monkeydevice.down_and_up)
#进入登录界面后输入用户名
Easy_device.type (by.id (' Id/username '), ' 18311029909 ')
#使密码文本框获得焦点
Easy_device.touch (by.id (' Id/password '), monkeydevice.down_and_up)
#输入密码
Easy_device.type (by.id (' Id/password '), ' 111111 ')
#点击 The Sign In button
Easy_device.touch (by.id (' id/login_btn '), monkeydevice.down_and_up)
#访问我的收藏模块
Easy_device.touch (by.id (' Id/relashicaimingxi '), monkeydevice.down_and_up)
#对当前界面截屏
Result =device.takesnapshot ()
#休眠2秒
Monkeyrunner.sleep (2)
#将截屏图片存入本地
Result.writetofile (' c:\\device.png ', ' png ')