Appium Appium 测试 Android 时,python 用例调用 Webdriver.remote 后无回应

blue_lana · 2014年03月21日 · 最后由 TD 回复于 2019年02月28日 · 1901 次阅读

大家好!遇到一个问题,希望大家能指点一下。我搭建好了 Appium 测试 Android 应用的测试环境,在运行 Python 编写的测试用例时,发现调用 Webdriver.remote 后,没有任何回应,Appium 的 log 如下:

info: Welcome to Appium v0.15.0 (REV a7b47d73a27074cc928cc5b325e5d4de1b6e5594)
info: Appium REST http interface listener started on 127.0.0.1:4723
info - socket.io started
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"sessionId":null,"desiredCapabilities":{"a
pp-package":"lana.test.hellolana","app":"F:\workspace\HelloLana\bin\HelloLan
a.apk","browserName":"","version":"4.2","device":"Android","app-activity":"lana.
test.hellolana.HelloLanaActivity"}}
info: Using local app from desiredCaps: F:\workspace\HelloLana\bin\HelloLana.apk

info: Creating new appium session 93723c5f-066c-4923-9536-ab582746d37d
info: Starting android appium
debug: Using fast reset? false
info: Preparing device for session
info: Checking whether app is actually present
info: Checking whether adb is present

然后过了十几分钟后,Appium 的 log 打印出:POST /wd/hub/session 200 600810ms
测试用例代码抛出如下异常:

Traceback (most recent call last):
File "F:\Appium\sample-code\examples\python\android_lana0319.py", line 22, in
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 71, in init
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 113, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 162, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 349, in execute
return self._request(command_info[0], url, body=data)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 417, in _request
resp = opener.open(request)
File "C:\Python27\lib\urllib2.py", line 394, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 412, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 372, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1199, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1170, in do_open
r = h.getresponse(buffering=True)
File "C:\Python27\lib\httplib.py", line 1027, in getresponse
response.begin()
File "C:\Python27\lib\httplib.py", line 407, in begin
version, status, reason = self._read_status()
File "C:\Python27\lib\httplib.py", line 371, in _read_status
raise BadStatusLine(line)
BadStatusLine: ''

环境配置和代码参数都多次检查过了,但是始终没有找到问题原因。希望大家能帮忙看看,万分谢谢!

共收到 4 条回复 时间 点赞

发现问题原因了,竟然是没有设置 ANDROID_HOME 造成的找不到 adb,我之前直接把 tools 和 platform-tools 的全路径加到环境变量 path 中的。使用 adb 命令没问题。但是 Appium 竟然找不到。

运行下 appium-doctor 试试看, 另外贴代码和日志请用 代码块

blue_lana 回复

我也遇到了你同样的问题。我用的是 ios 的真机,你能把解决方法写清楚些吗?

qiaoxiaozheng 回复

我也是 ios 的真机,我是执行一段时间后突然在输入的时候无响应,后面就报错 could not be run on failure:BadStatusLine: '',请问你后面解决了吗?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册