0

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:

enter image description here

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)
EGHDK
  • 17,818
  • 45
  • 129
  • 204
  • It doesn't seem a problem related with AndroidViewClient but with Windows monkeyrunner in general if it cannot execute a script which is specified by its absolute path. – Diego Torres Milano Apr 19 '13 at 07:11
  • If I put test.py into AndroidViewClient/src it works! – EGHDK Apr 19 '13 at 07:14
  • Okay, I moved dump.py instead of copying by accident. Anyway... calling it works. But I still get the no module named drmilano error. – EGHDK Apr 19 '13 at 07:20

2 Answers2

0

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
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Does this environment variable look set up properly? `C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\src` – EGHDK Apr 19 '13 at 06:46
  • This first part (`C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient`) depends on how you unzipped the file. Let's assume is correct (you can verify it cd'ing into it). The second part (`\src`) it's not needed, you have to remove it. – Diego Torres Milano Apr 19 '13 at 06:50
  • Okay, I believe the path is correct. Please see my updated question. I try to run dump.py but it does not work. – EGHDK Apr 19 '13 at 06:51
  • Can you cd into `C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient` ? – Diego Torres Milano Apr 19 '13 at 06:52
  • Correct! this is the directory you have to set as the value of the environment variable `ANDROID_VIEW_CLIENT_HOME`. – Diego Torres Milano Apr 19 '13 at 06:56
  • I see. It seems that in Windows `monkeyrunner` changes the directory to `tools`. Specify the absolute path for the script: `monkeyrunner \path\to\my\script.py` – Diego Torres Milano Apr 19 '13 at 06:59
  • Oh I was running `monkeyrunner dump.py`, but you need me to run `monkey runner C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\examples\dump.py`? – EGHDK Apr 19 '13 at 07:00
  • In you command line, instead of `monkeyrunner dump.py` use `monkeyrunner \path\to\my\dump.py` – Diego Torres Milano Apr 19 '13 at 07:01
  • Okay, I typed out the full path. Get a different message this time. Check my updated question. – EGHDK Apr 19 '13 at 07:04
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28492/discussion-between-eghdk-and-dtmilano) – EGHDK Apr 19 '13 at 07:07
0

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
EGHDK
  • 17,818
  • 45
  • 129
  • 204
  • 1
    Glad to hear you found the solution. What you changed is exactly (well in other OSs like Linux or OSX, it is) what dump.py does: `sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))`, so if you feel like exploring try to print `sys.path` content to verify what is the difference. The `\` (backslashes) perhaps. – Diego Torres Milano Apr 19 '13 at 22:43