从网站(Yii PHP框架)执行脚本AndroidViewClient/culebra


Execute script AndroidViewClient/culebra from website (Yii PHP framework)

我有一个带有AndroidViewClient/culebra的脚本,如果它由以下命令行执行,效果会很好:

python myscripttest.py emulator-5554

但由于我正在使用Yii(PHP)作为网站。使用CCD_ 1来执行脚本。它显示了这个错误。

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

ANDROID_HOME和ANDROID_VIEW_CLIENT_HOME在环境中定义:

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

可能是因为脚本是从网站上调用的?

编辑-ANDROIDVIEWCLIENT更新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)

但是它定义的ANDROID_HOME:

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

脚本myscripttest.py是:

#!/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")

升级到AVC 11.0.10,消息将更加明确。这将帮助您识别问题。

消息将是:

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

编辑

可能声明了ANDROID_HOME,但没有导出。尝试:

export ANDROID_HOME

在执行脚本的环境中。