开发者

Monkey Runner import giving error

开发者 https://www.devze.com 2023-04-07 19:39 出处:网络
i created an empty file an named it something.py, and then i just copied the lines of code from the android developer website. However, if i try to run it, i get an

i created an empty file an named it something.py, and then i just copied the lines of code from the android developer website. However, if i try to run it, i get an

ImportError: No module named com.android.monkeyrunner

Is there something i am missing? There doesn't seem to be anything at the android developer website that addresses this issue. Here are the lines of code

       from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
       device = MonkeyRunner.waitForConnection()
       device.installPackage('myproject/bin/Stamp_Client.apk')
       package = 'com.example.main'
       activity = 'com.example.Stamp_Client'
       runComponent = package + '/' + activity
       device.startActivity(component=runComponent)
       device.press('KEYCODE_BUTTON_SELECT','DOWN_AND_UP')
       device.press('KEYCODE_U','DOWN_AND_UP')
       device.press('KEYCODE_S','DOWN_AND_UP')
       device.press('KEYCODE_E','DOWN_AND_UP')
       device.press('KEYCODE_R','DOWN_AND_UP')
       device.press('KEYCODE_ENTER','DOWN_AND_UP')
       device.press('KEYCODE_P','DOWN_AND_UP')
       device.press('KEYCODE_A','DOWN_AND_UP')
       device.press('KEYCODE_S','DOWN_AND_UP')
       device.press('KEYCODE_S','DOWN_AND_UP')
       device.press('KEYCODE_ENTER','DOWN开发者_C百科_AND_UP')
       device.press('KEYCODE_ENTER','DOWN_AND_UP')


Make sure you run:

$ monkeyrunner yourfile.py

instead of:

$ python yourfile.py


I guess you are missing the shebang:

#! /usr/bin/env monkeyrunner

that is if you are using Linux or OSX, for Windows you probably have to create a batch file.

0

精彩评论

暂无评论...
验证码 换一张
取 消