2013-04-25 2 views
2

에뮬레이터에서 androiddriver를 성공적으로 설정할 수 있었지만 httplib 오류를 해결하는 데 어려움이 있습니다. 다음은 Mac에서 android sdk를 설정 한 후 취한 조치입니다.Androiddriver Python Bindings httplib

1. ./adb devices, which returned emulator-5554 
2. ./adb emulator-5554 -s forward tcp:8080 tcp:8080 
3. visited http://localhost:8080/wd/hub/status in my browser and received a { status: 0 } 
4. In the python shell (tried this on both python 2.7 & 2.6), I did: 

>> from selenium import webdriver 
>> from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 
>> driver = webdriver.Remote("http://localhost:8080/wd/hub",  webdriver.DesiredCapabilities.ANDROID) 
>> driver.get("http://www.google.com") 

일부 경우 드라이버 변수를 설정할 때 오류가 발생하며 때로는 오류가 발생합니다. driver.get 명령에서도 마찬가지입니다.

스택 트레이스는 다음과 같습니다 :

File "<stdin>", line 1, in <module> 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 177, in get 
    self.execute(Command.GET, {'url': url}) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 163, in execute 
    response = self.command_executor.execute(driver_command, params) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 349, in execute 
    return self._request(url, method=command_info[0], data=data) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 396, in _request 
response = opener.open(request) 
    File  "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 394, in open 
    response = self._open(req, data) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 412, in _open 
'_open', req) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 372, in _call_chain 
    result = func(*args) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1199, in http_open 
    return self.do_open(httplib.HTTPConnection, req) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1170, in do_open 
    r = h.getresponse(buffering=True) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1027, in getresponse 
response.begin() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 407, in begin 
version, status, reason = self._read_status() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 371, in _read_status 
    raise BadStatusLine(line) 
httplib.BadStatusLine: '' 

다른 사람이에 대한 해결책의 아이디어가 있습니까?

+2

업데이트 - 이전 버전의 android-server apk를 설치했습니다 (android- 2.32.0 전에). – qaduderino

+2

with android-server-2.21.0.apk [link] (https://code.google.com/p/selenium/downloads/detail?name=android-server-2.21.0.apk&can=2&q=) 이것은입니다. 잘 작동합니다. – qaduderino

+0

나는 하루 종일 작동하도록 노력해 왔습니다. APK가 문제라는 것이 나에게는 결코 발생하지 않았다. –

답변

0

당신이 말했듯이 이것은 android-server의 newer version에서 수정되었습니다. 그러나 업데이트 할 수없는 사용자는로드하는 실제 페이지에 페이지가 미리로드되지 않았다고 가정하기 때문에 드라이버의 문제가 발생합니다. Selenium은 드라이버에서 일부 HTTP 헤더를 수신하며 상태 표시 줄은 유효하지 않습니다. 예를 들어,

대신 HTTP/1.0 200 대신 상태 표시 줄이 비어 있습니다 (위와 같음).

이 문제를 해결할 수있는 한 가지 방법은 페이지가로드 된 것으로 간주되어 연결을 설정하기에 충분한 시간 동안 기다리는 것입니다.

나는 보통 코드 줄이 예외가

: 호출이 성공할 때까지

android = webdriver.Remote(command_executor='http://127.0.0.1:8080/wd/hub', desired_capabilities=capabilities.ANDROID) 

그래서 해결하기 위해, 난 그냥 기다릴 코드를 변경 : 나는 여전히

android = None 
while android is None: 
    try: 
     android = webdriver.Remote(command_executor='http://127.0.0.1:8080/wd/hub', desired_capabilities=capabilities.ANDROID) 
    except: 
     time.sleep(1) 
     pass 

주 내가 2.3.2 APK에서 2.2.1로 다운 그레이드 할 때까지 save_screenshotBadStatusLine에 문제가 발생했습니다. APK