I am interested in making use of the ViewClient extension for MonkeyRunner having run into Broken Pipe issues with pure MonkeyRunner.
I need to still use X/Y coordinates in the device.press(...), device.touch(...), device.drag(...) functions for some of the tests (not a normal android hierarchy) so for this reason I need to import MonkeyRunner into the ViewClient Phyton script - however for the android Apps part of the testing I can use ViewClient proper to search for ID's in the heirarchy. Unless someone knows how to set hardcoded X/Y in ViewClient before calling vc.touch()/vc.drag() etc?
I therefore have the following header to my Python script that attempts to pull in the ViewClient environment and MonkeyRunner path. However running the script always results in the same error:
ImportError: No module named android.monkeyrunner
The part of the script that sets the environment up is structured this way (Environment - Ubuntu 12.04 LTS)
#! /usr/bin/env python
# Import Class Files
import sys
import os
# This must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails.
# PyDev sets PYTHONPATH, use it
try:
for p in os.environ['PYTHONPATH'].split(':'):
if not p in sys.path:
sys.path.append(p)
except:
pass
try:
sys.path.append(os.environ['ANDROID_VIEW_CLIENT_HOME'])
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
sys.path.append(os.path.join(os.environ['ANDROID_SDK_ROOT'], 'tools/lib/monkeyrunner.jar'))
sys.path.append(os.path.join(os.environ['ANDROID_SDK_ROOT'], 'tools/lib'))
except:
pass
print sys.path
from com.dtmilano.android.viewclient import ViewClient, View
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
So the output of the above looks like this:
mactwixs:~/AndroidViewClient/examples$ ./monkeyscript3.py
['/home/mactwixs/AndroidViewClient/examples', '/home/mactwixs/AndroidViewClient/examples', '/home/mactwixs/AndroidViewClient', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '', '/home/mactwixs/AndroidViewClient', '/home/mactwixs/AndroidViewClient/src', '/home/mactwixs/dev_env/ADT/sdk/tools/lib/monkeyrunner.jar', '/home/mactwixs/dev_env/ADT/sdk/tools/lib']
Traceback (most recent call last):
File "./monkeyscript3.py", line 41, in <module>
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
ImportError: No module named android.monkeyrunner
Thanks!
UPDATE:
Interestingly:
mactwixs:~/AndroidViewClient/examples$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path_hooks
[<type 'zipimport.zipimporter'>]
>>>
Should there not be <type 'org.python.core.JavaImporter'>
too?
UPDATE2:
so the difference is:
mactwixs:~/AndroidViewClient/examples$ python
**Python** 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
mactwixs:~/AndroidViewClient/examples$ monkeyrunner
**Jython** 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:54:35)
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_24
>>>
....so let me try intsalling Jython!
UPDATE3:
Nope. Now it fights with ViewClient so I'm back to square one... and I have found the check-import.py that is supplied with ViewClient. The out of this makes me think something isn't set up quite right as monkeyrunner rather than python is being called for viewclient.py & adbclient.py ...
mactwixs:~/AndroidViewClient/examples$ monkeyrunner check-import.py --debug
sys.path= ['/home/mactwixs/dev_env/ADT/sdk/tools/lib/monkeyrunner.jar', '/home/mactwixs/AndroidViewClient/examples', '/home/mactwixs/dev_env/ADT/sdk/tools/lib/Lib', '/home/mactwixs/dev_env/ADT/sdk/tools/lib/jython-standalone-2.5.3.jar/Lib', '__classpath__', '__pyclasspath__/', '/home/mactwixs/AndroidViewClient/src']
/home/mactwixs/AndroidViewClient/src/com/dtmilano/android/viewclient.py:27: RuntimeWarning:
You should use a 'python' interpreter, not 'monkeyrunner' for this module
warnings.warn(
/home/mactwixs/AndroidViewClient/src/com/dtmilano/android/adb/adbclient.py:26: RuntimeWarning:
You should use a 'python' interpreter, not 'monkeyrunner' for this module
warnings.warn(
OK