Can't get AndroidViewClient example code to run

北城余情 提交于 2020-01-25 12:50:14

问题


AndroidViewClient is a github repo that allows you to call on views directly, without specifying exact coordinates with monkeyrunner. I'm having trouble actually using it though.

Note: I'm using Windows

In cmdline if I type:

monkeyrunner test.py

and test.py consists of:

# 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)

Then the actionBar overflow button get's clicked.

If I edit test.py to any of the AndroidViewClient examples it will doesn't do anything.

Any ideas? I'm not sure if I'm implementing AndroidViewClient correctly.

EDIT:

The only thing I did to setup AndroidViewClient is download the .zip from github and then I added it to my environment variables like this:

When I try to run 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)

Typing in the full path:

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)

回答1:


From AndroidViewClient wiki:

Installation AndroidViewClient does not require installation to be used. You only need to download the source distribution and set the environment variable ANDROID_VIEW_CLIENT_HOME or PYTHONPATH to allow the monkeyrunner interpreter to find the required modules.

Expand the downloaded ZIP file and set the environment variable accordingly.

Then if you are intending to run, for example dump.py the next step is:

monkeyrunner dump.py



回答2:


In dump.py changed:

from com.dtmilano.android.viewclient import ViewClient

to:

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

and it worked now. Here's a sample output from my app.

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


来源:https://stackoverflow.com/questions/16098500/cant-get-androidviewclient-example-code-to-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!