主要參考了這篇文章,感謝作者的貢獻(xiàn)
成都服務(wù)器托管,創(chuàng)新互聯(lián)提供包括服務(wù)器租用、服務(wù)器托管、帶寬租用、云主機(jī)、機(jī)柜租用、主機(jī)租用托管、CDN網(wǎng)站加速、主機(jī)域名等業(yè)務(wù)的一體化完整服務(wù)。電話咨詢:13518219792
http://forum.xda-developers.com/showthread.php?t=2566234
1.Monkeyrunner
Monkeyrunner是一個(gè)自動(dòng)化的測(cè)試工具,我們用它做產(chǎn)品的黑盒測(cè)試。它提供了Python API使我們不用修改Android代碼,而是用python程序來(lái)控制我們的設(shè)備模擬器。我們可以用python來(lái)安裝應(yīng)用,測(cè)試包,運(yùn)行,發(fā)起按鍵事件,獲取并保存用戶界面的截圖。
Monkeyrunner工具設(shè)計(jì)的主要目的,是在框架的層面上測(cè)試應(yīng)用和設(shè)備并為運(yùn)行單元測(cè)試套件。當(dāng)然,你也可以用它來(lái)做其他的事。
Monkeyrunner官方網(wǎng)站
http://developer.android.com/tools/help/monkeyrunner_concepts.html
2.基本條件:
1. Windows 7/8 OS
2. Java 6
3. Eclipse
4. Anroid設(shè)備最好要能運(yùn)行 2.3.4及以上版本(非強(qiáng)制性)
5. Python
6. Jython
7. 一個(gè)待測(cè)試的應(yīng)用
3.安裝
下載安裝Python:http://www.python.org/getit/
接下來(lái)通過eclipse的market place下載eclipse的PyDev插件
help->Install New Soft
地址是:http://pydev.org/updates
配置 Jython interpreters:參考這篇博客(其中也包含了Pydev的安裝過程),我就不重復(fù)造車了
http://blog.csdn.net/zhubaitian/article/details/39803205
配置 Python interpreters:
Window->Preferences->PyDev->Interpreters->-Python interpreters
4.建工程
這樣最基本的配置就完成了,接下來(lái)新建一個(gè)文件
New -> PyDev Project -> 為工程命名并選擇 Jython
如下:
右鍵你的工程,new-->PyDev-->new module
選擇empty
寫入代碼
關(guān)于monkeyrunner的語(yǔ)法,官網(wǎng)講的很清楚:
http://developer.android.com/tools/help/monkeyrunner_concepts.html
例如我自己的代碼如下
# Imports the monkeyrunner modules used by this program from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice from symbol import if_stmt from sys import exit # Connects to the current device, returning a MonkeyDevice object device = MonkeyRunner.waitForConnection() if not device: print("no device") exit # Installs the Android package. Notice that this method returns a boolean, so you can test # to see if the installation worked. device.installPackage('F:/android-space/OrangeLife_2.0/bin/OrangeLife_2.0.apk') # sets a variable with the package's internal name package = 'com.curry.ams' # sets a variable with the name of an Activity in the package activity = 'com.curry.ams.user.LoginActivity' # sets the name of the component to start runComponent = package + '/' + activity # Runs the component device.startActivity(component=runComponent) # Presses the Menu button device.touch(285,488, MonkeyDevice.DOWN_AND_UP) device.type('13313933088') device.touch(432,648, MonkeyDevice.DOWN_AND_UP) device.type('ysclyy2413567') device.touch(573,1133, MonkeyDevice.DOWN_AND_UP) # Takes a screenshot result = device.takeSnapshot() # Writes the screenshot to a file result.writeToFile('F:/android-space/shot1.png','png')
5.運(yùn)行
運(yùn)行前要先進(jìn)行配置:
Run-->Extenal Tools-->Extenal Tools configration
Locations:這里填的是你android sdk文件夾下,tool中的monkeyrunner.bat
Working Directory:你的工作目錄,你的.apk文件要在該工作目錄中
Arguments:要執(zhí)行的.py文件的路徑
點(diǎn)擊run 就開始運(yùn)行了
網(wǎng)站名稱:eclipse下Monkeyrunner平臺(tái)搭建Pydex
分享網(wǎng)址:http://bm7419.com/article26/jdehjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站排名、品牌網(wǎng)站制作、做網(wǎng)站、ChatGPT、微信公眾號(hào)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)