2012-02-06 45 views

回答

0

我使用猴子在模擬器中駕駛應用程序。

我有一個Python腳本得到餵給monkeyrunner工具。這主要來自Android開發者website上的示例。 可以調用活動並對它們做出響應。 例如,我在這裏調用一個活動,然後又運行另一個;在那一點上,我輸入4位數字,並在'確定'按鈕對應的屏幕上'點擊'座標100,400。

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice 

if __name__ == "__main__": 
    # 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('myproject/bin/MyApplication.apk') 

    # sets a variable with the package's internal name 
    package = 'com.mypackage' 

    # sets a variable with the name of an Activity in the package 
    activity = 'com.mypackage.myactivity' 

    # sets the name of the component to start 
    runComponent = package + '/' + activity 

    # Runs the component 
    device.startActivity(component=runComponent) 

    if device.getProperty('am.current.comp.class') == 'com.mypackage.anotheractivity': 
     device.type('0000') 
     # Click the 'Enter' button on screen at coordinates 100,400 
     device.touch(100, 600, 'DOWN_AND_UP') 

我希望有幫助。