MonkeyRunner的使用
要使用MonkeyRunner,就要学习使用Python,哎
先抄一段官方doc里的代码
作用是启动一个程序(应该是启动程序默认的Activity),然后按MENU键,并截屏
# Imports the monkeyrunner modules used by this programfrom com.android.monkeyrunner import MonkeyRunner as mrfrom com.android.monkeyrunner import MonkeyDevice as md# Connects to the current device, returning a MonkeyDevice objectdevice = mr.waitForConnection()# sets a variable with the package's internal namepackage = 'com.example.android.myapplication'# sets a variable with the name of an Activity in the packageactivity = 'com.example.android.myapplication.MainActivity'# sets the name of the component to startrunComponent = package + '/' + activity# Runs the componentdevice.startActivity(component=runComponent)# Presses the Menu buttondevice.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)# Takes a screenshotresult = device.takeSnapshot()# default folder name to save snapshotsnapshot = 'E:\\tmp\\'# Writes the screenshot to a fileresult.writeToFile(snapshot + 'shot1.png','png')
import sysimport os# this must be imported before MonkeyRunner and MonkeyDevice,# otherwise the import failsANDROID_VIEW_CLIENT_HOME = os.environ['ANDROID_VIEW_CLIENT_HOME']sys.path.append(ANDROID_VIEW_CLIENT_HOME + '/src')from com.dtmilano.android.viewclient import ViewClient
# Support from 2.3.3from com.android.chimpchat.hierarchyviewer import HierarchyViewerfrom com.android.hierarchyviewerlib.device import ViewNodehv = device.getHierarchyViewer() vn = hv.findViewById('id/icon_menu')