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

从网站(Yii PHP框架)执行脚本AndroidViewClient/culebra,php,python-2.7,android-sdk-tools,androidviewclient,Php,Python 2.7,Android Sdk Tools,Androidviewclient,我有一个带有AndroidViewClient/culebra的脚本,如果它是通过命令行执行的,则可以正常工作,如: python myscripttest.py emulator-5554 但当我在网站上使用Yii(PHP)时。该脚本是使用subprocess.call(python myscripttest.py,shell=True)执行的。它显示了这个错误 File "/var/www/html/u_script_files/myscripttest.py", line 47, in

我有一个带有AndroidViewClient/culebra的脚本,如果它是通过命令行执行的,则可以正常工作,如:

python myscripttest.py emulator-5554
但当我在网站上使用Yii(PHP)时。该脚本是使用
subprocess.call(python myscripttest.py,shell=True)
执行的。它显示了这个错误

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
可能是因为脚本是从网站调用的

编辑-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)
脚本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")
#/usr/bin/python
进口稀土
导入系统
导入操作系统
导入时间
从com.dtmilano.android.viewclient导入viewclient
标签='CULEBRA'
_s=5
_v='--verbose'在sys.argv中
def返回(自我):
self.shell('input keyevent KEYCODE\u BACK')
def主页(自我):
self.shell('input keyevent KEYCODE\u HOME')
def输入(自我):
self.shell('input keyevent KEYCODE\u ENTER')
def保存结果(fr、设备、消息):
f_结果=打开(fr,‘wt’)
如果msg为None:
msg='无'
f_结果写入(消息编码('utf-8'))
f_result.close()
#定义包和主活动名称
package=“com.evernote”
activity=“ui.HomeActivity”
#设置要启动的组件的名称
runComponent=package+“/。”+活动
kwargs1={'ignoreversioncheck':False,'verbose':True,'ignoresecuredevice':False}
设备,serialno=ViewClient.connectToDeviceOrExit(**kwargs1)
#运行组件
打印(“启动应用程序:Evernote”)
device.startActivity(组件=运行组件)
时间。睡眠(5)
kwargs2={'forceviewserveruse':False,'useuiautomatorhelper':False,'ignoreuiautomatorkilled':True,'autodump':False,'startviewserver':True,'compresseddump':True}

vc=ViewClient(设备,序列号,**kwargs2)升级到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\u HOME
,但未导出。 尝试:


在您正在执行脚本的环境中。

如果不查看
myscripttest.py
并了解更多有关环境的信息,就很难判断发生了什么。但是,您可能会对使用
ANDROID\u VIEW\u CLIENT\u HOME
感到困惑,因为您在环境中将其设置为指向repo,但随后使用的是pip/easy\u install安装包中的AVC。为什么要使用python executible命令来运行AndroidViewClient脚本?为什么不直接使用这个命令:culebra myscripttest.py emulator-5554I已经更新了AVC并再次执行了脚本。我仍然有错误。我也在编辑区发布我的脚本。谢谢。我必须将我的ANDROID_主页路径添加到“common.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")
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
export ANDROID_HOME