转:MonkeyRunner使用例子
上一篇 /
下一篇 2013-01-28 16:18:45
# Imports the monkeyrunner modules used by this programfrom com.android.monkeyrunner import MonkeyRunner, MonkeyDeviceimport sysdef getDeviceInfor(device): deviceInfor = "device: " + str(device.getProperty("device")) + "\n" deviceInfor = deviceInfor + "model: " + str(device.getProperty("model")) + "\n" deviceInfor = deviceInfor + "board: " + str(device.getProperty("board")) + "\n" deviceInfor = deviceInfor + "brand: " + str(device.getProperty("brand")) + "\n" deviceInfor = deviceInfor + "fingerprint: " +str(device.getProperty("fingerprint")) + "\n" deviceInfor = deviceInfor + "product: " + str(device.getProperty("product")) +"\n" deviceInfor = deviceInfor + "type: " + str(device.getProperty("type")) + "\n" deviceInfor = deviceInfor + "manufacturer: " +str(device.getProperty("manufacturer")) + "\n" deviceInfor = deviceInfor + "CPU_ABI: " + str(device.getProperty("CPU_ABI")) +"\n" deviceInfor = deviceInfor + "version.release: " +str(device.getProperty("version.release")) + "\n" deviceInfor = deviceInfor + "version.sdk: " +str(device.getProperty("version.sdk")) + "\n" deviceInfor = deviceInfor + "version.codename: " +str(device.getProperty("version.codename")) + "\n" deviceInfor = deviceInfor + "width: " + str(device.getProperty("width")) + "\n" deviceInfor = deviceInfor + "height: " + str(device.getProperty("height")) + "\n" deviceInfor = deviceInfor + "density: " + str(device.getProperty("density")) +"\n" deviceInfor = deviceInfor + "realtime: " + str(device.getProperty("realtime")) +"\n" return deviceInfordef connectDevice(): # Connects to the current device, returning a MonkeyDevice object print "MonkeyRunner is connecting your device" print "waiting for connection..." device = MonkeyRunner.waitForConnection(20) try: print getDeviceInfor(device) except : #print inst print "Can not Find your devices, Please Check!" sys.exit(1) print "MonkeyRunner has been connected!!" return device# Installs the Android package. Notice that this method returns a boolean, so you can test# to see if the installation worked.#device.installPackage('myproject/bin/MyApplication.apk')# sets a variable with the package's internal name#package = 'com.example.android.myapplication'# sets a variable with the name of an Activity in the package#activity = 'com.example.android.myapplication.MainActivity'# sets the name of the component to start#runComponent = package + '/' + activity# Runs the component#device.startActivity(component=runComponent)# Presses the Menu button#device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)def Call(device): device.wake() device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP) print "Press Home Key" MonkeyRunner.sleep(3) print "Sweep screen to unlock the device" device.drag((0,400),(700,400),0.1,50) MonkeyRunner.sleep(3) print "Call 10086" device.startActivity(uri='tel:10086') MonkeyRunner.sleep(1) device.press('KEYCODE_CALL',MonkeyDevice.DOWN_AND_UP) MonkeyRunner.sleep(10)
收藏
举报
TAG: