1. monkeyrunner的位置
學習monkeyrunner的童鞋們應該都有自己安裝的android sdk環(huán)境,而monkeyrunner的工具位于android sdk/tools/monkeyrunner.bat文件
2.如何快速的在命令行打開monkeyrunner
將
android sdk/tools目錄加入到環(huán)境變量的path中
3.先運行http://developer.android.com/tools/help/monkeyrunner_concepts.html官網(wǎng)上的例子程序
注:monkeyrunner只是一組API,需要使用python腳本去調(diào)用
分析:program.py文件
- # Imports the monkeyrunner modules used by this program
- from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
- import time
-
- # Connects to the current device, returning a MonkeyDevice object
- device = MonkeyRunner.waitForConnection() #連接設備
-
- # Installs the Android package. Notice that this method returns a boolean, so you can test
- # to see if the installation worked.
- device.installPackage('./360explorer-4.2.8-0910.4.apk') #安裝apk包,./表示該包和monkeyrunner.bat在同一個目錄
-
- package = 'com.qihoo.explorer' #apk包名
- activity = 'com.qihoo.explorer.HomeActivity' #apk的activity名稱, 包名和anctivity名稱可以通過aapt命令獲取
- runComponent = package + '/' + activity
-
- device.startActivity(component=runComponent) #啟動應用程序
- device.press('KEYCODE_MENU','DOWN_AND_UP') #KEYCODE_MENU表示菜單鍵,打開菜單
- time.sleep(10) #暫停10秒
- result =device.takeSnapshot() #截圖
- result.writeToFile('./shot1.png','png') #將截圖存放到和monkeyrunner.bat同一個目錄下的shot1.png中
運行:
命令行下執(zhí)行monkeyrunner program.py
提示錯誤如下:
Can't open specified script file
Usage: monkeyrunner [options] SCRIPT_FILE
-s MonkeyServer IP Address.
-p MonkeyServer TCP Port.
-v MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)
解決辦法:
monkeyrunner program.py的全路徑
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。