1

I have a script with AndroidViewClient/culebra that works fine if it's executed by command line like:

python myscripttest.py emulator-5554

But as I'm using Yii(PHP) for Website. the script was executed using subprocess.call(python myscripttest.py, shell=True). And it shows this error.

File "/var/www/html/u_script_files/myscripttest.py", line 47, in <module>
vc = ViewClient(device, serialno, **kwargs2)
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.0.7-py2.7.egg/com/dtmilano/android/viewclient.py", line 2352, in __init__
adb = obtainAdbPath()
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.0.7-py2.7.egg/com/dtmilano/android/common.py", line 116, in obtainAdbPath
raise Exception('adb="%s" is not executable. Did you forget to set ANDROID_HOME in the environment?' % adb)
Exception: adb="adb" is not executable. Did you forget to set ANDROID_HOME in the environment?
Exception AttributeError: "ViewClient instance has no attribute 'uiAutomatorHelper'" in <bound method ViewClient.__del__ of <com.dtmilano.android.viewclient.ViewClient instance at 0x7f1ae981dc68>> ignored

The ANDROID_HOME and ANDROID_VIEW_CLIENT_HOME are defined on the environment:

$ echo $ANDROID_HOME
/home/experts/android-sdk-linux/
$ echo $ANDROID_VIEW_CLIENT_HOME
/home/experts/AndroidViewClient-master/

It could be because the script is called from the website?

EDIT - ANDROIDVIEWCLIENT UPDATED 11.0.10:

Connecting to a device with serialno=emulator-5558 with a timeout of 60 secs...
Connected to device with serialno=emulator-5558
Actual device serialno=emulator-5558
Starting App: Evernote
Traceback (most recent call last):
File "/var/www/html/u_script_files/myscripttest.py", line 47, in <module>
vc = ViewClient(device, serialno, **kwargs2)
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.0.10-py2.7.egg/com/dtmilano/android/viewclient.py", line 2356, in __init__
adb = obtainAdbPath()
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.0.10-py2.7.egg/com/dtmilano/android/common.py", line 128, in obtainAdbPath
 if not os.environ['ANDROID_HOME']:
File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)

But the ANDROID_HOME it's defined:

$ echo $ANDROID_HOME
/home/experts/android-sdk-linux/

The script myscripttest.py is:

#!/usr/bin/python

import re
import sys
import os
import time

from com.dtmilano.android.viewclient import ViewClient

TAG = 'CULEBRA'

_s = 5
_v = '--verbose' in sys.argv

def back(self):
    self.shell('input keyevent KEYCODE_BACK')

def home(self):
    self.shell('input keyevent KEYCODE_HOME')

def enter(self):
    self.shell('input keyevent KEYCODE_ENTER')

def saveresult(fr, device, msg):
f_result = open(fr, 'wt')
if msg is None:
    msg = 'None'
f_result.write(msg.encode('utf-8'))
f_result.close()

# define package and Main activity name
package = "com.evernote"
activity = "ui.HomeActivity"

# sets the name of the component to start
runComponent = package + "/." + activity
kwargs1 = {'ignoreversioncheck': False, 'verbose': True, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)

# Runs the component
print ("Starting App: Evernote")
device.startActivity(component=runComponent)
time.sleep(5)

kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}

vc = ViewClient(device, serialno, **kwargs2) <== HERE IT IS THE ERROR

#vc.dump(window='-1')
vc.dump()

# class=android.widget.FrameLayout
no_id1 = vc.findViewByIdOrRaise("id/no_id/1")
CodeIK
  • 177
  • 1
  • 14
  • 1
    Difficult to tell what's happening without seeing `myscripttest.py` and knowing more about the environment. However, you may be confused about the use of `ANDROID_VIEW_CLIENT_HOME` because you are setting it in your environment to point to the repo but then you are using **AVC** from the pip/easy_install installed package. – Diego Torres Milano Dec 30 '15 at 21:25
  • Why are you using the **python** executible command to run an AndroidViewClient script? Why not just use this command: **culebra myscripttest.py emulator-5554** – IgorGanapolsky Jul 11 '16 at 15:07

1 Answers1

1

Upgrade to AVC 11.0.10 and the messages will be more explicit. This will help you identify the problem.

The message will be:

Exception: adb="adb" is not executable. Did you forget to set ANDROID_HOME in the environment?

These files we unsuccessfully checked to find a suitable 'adb' executable:
    /opt/android-sdk/platform-tools/adb
    /Users/user/android/platform-tools/adb
    /Users/user/android-sdk/platform-tools/adb
    adb
    /usr/local/bin/adb
    /usr/bin/adb
    /bin/adb
    /usr/sbin/adb
    /sbin/adb
    /opt/X11/bin/adb
    /Library/Frameworks/Python.framework/Versions/2.7/bin/adb
    /Users/user/Library/Android/sdk/tools/adb
    /Users/user/Library/Android/sdk/platform-tools/adb
    /Users/user/bin/adb

EDIT

Perhaps ANDROID_HOME is declared but not exported. Try:

export ANDROID_HOME

in the environment you are executing the script.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • I have updated AVC and executed again the script. I still have error. I post my Script too at the EDIT section. Thanks. – CodeIK Jan 04 '16 at 14:14
  • I have to add my ANDROID_HOME path into "common.py" and now it works fine! Thanks so much!! – CodeIK Jan 05 '16 at 17:02