无法获取AndroidViewClient示例代码来运行

时间:2013-04-19 06:23:47

标签: android monkeyrunner

AndroidViewClient是一个github仓库,允许您直接调用视图,而无需使用monkeyrunner指定精确坐标。我实际上在使用它时遇到了麻烦。

注意:我正在使用Windows

如果我输入cmdline:

monkeyrunner test.py

和test.py包含:

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

# Presses the Menu button
device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)

然后单击actionBar溢出按钮。

如果我将test.py编辑到任何AndroidViewClient示例,它将不会执行任何操作。

有什么想法吗?我不确定我是否正确实现了AndroidViewClient。

修改

我设置AndroidViewClient的唯一方法是从github下载.zip然后我将它添加到我的环境变量中:

enter image description here

当我尝试运行monkeyrunner dump.py时:

130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Scri
pt terminated due to an exception
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Trace
back (most recent call last):
  File "C:\Users\EgamerHDK\android-sdk\tools\dump.py", line 29, in <module>
    from com.dtmilano.android.viewclient import ViewClient
ImportError: No module named dtmilano

130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.ImportError(Py.java:264)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.import_logic(imp.java:692)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.import_name(imp.java:746)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.importName(imp.java:791)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.ImportFunction.__call__(__builtin__.java:1236)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyObject.__call__(PyObject.java:367)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.__builtin__.__import__(__builtin__.java:1207)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.importFromAs(imp.java:869)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.importFrom(imp.java:845)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.pycode._pyx0.f$0(C:\Users\EgamerHDK\android-sdk\tools\dump.py:78)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.pycode._pyx0.call_function(C:\Users\EgamerHDK\android-sdk\tools\dump.
py)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyTableCode.call(PyTableCode.java:165)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyCode.call(PyCode.java:18)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.runCode(Py.java:1197)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)

130419 02:46:57.869:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:18
9)

输入完整路径:

C:\Users\EGamerHDK\android-sdk\tools>monkeyrunner C:\AndroidViewClient-master\Andro
idViewClient-master\AndroidViewClient\examples\dump.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)

2 个答案:

答案 0 :(得分:0)

来自AndroidViewClient wiki

  

安装AndroidViewClient不需要安装   用过的。您只需要下载源代码分发并设置   环境变量ANDROID_VIEW_CLIENT_HOME或PYTHONPATH允许   monkeyrunner解释器找到所需的模块。

展开下载的ZIP文件并相应地设置环境变量。

然后,如果您打算运行,例如dump.py,则下一步是:

monkeyrunner dump.py

答案 1 :(得分:0)

在dump.py中更改:

from com.dtmilano.android.viewclient import ViewClient

为:

sys.path.append('C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\src')
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from com.dtmilano.android.viewclient import ViewClient

现在有效了。这是我的应用程序的示例输出。

android.widget.FrameLayout id/no_id/1
   android.widget.LinearLayout id/no_id/2
      android.widget.FrameLayout id/no_id/3
         android.view.View id/no_id/4
            android.widget.FrameLayout id/no_id/5
               android.widget.ImageView id/no_id/6
            android.widget.LinearLayout id/no_id/7
               android.widget.LinearLayout id/no_id/8
                  android.widget.TextView id/no_id/9 Tabs+SwipeCompatable
            android.widget.LinearLayout id/no_id/10
               android.widget.ImageButton id/no_id/11
         android.widget.HorizontalScrollView id/no_id/12
            android.widget.LinearLayout id/no_id/13
               android.widget.LinearLayout id/no_id/14
                  android.widget.TextView id/no_id/15 SECTION 1
               android.widget.LinearLayout id/no_id/16
                  android.widget.TextView id/no_id/17 SECTION 2
               android.widget.LinearLayout id/no_id/18
                  android.widget.TextView id/no_id/19 SECTION 3
      android.widget.FrameLayout id/no_id/20
         android.support.v4.view.ViewPager id/no_id/21
            android.widget.FrameLayout id/no_id/22
               android.widget.TextView id/no_id/23 1