尝试为我们的Django项目运行一些功能测试,但是我们遇到了一个很难调试的错误。我们已尝试设置sauce connect,但我们的构建失败了。
您可以看到构建的results,但这里是堆栈跟踪。
======================================================================
ERROR: test_page_load (quote_me.tests.FunctionalTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/opt/python/3.6.3/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/opt/python/3.6.3/lib/python3.6/ssl.py", line 814, in __init__
self.do_handshake()
File "/opt/python/3.6.3/lib/python3.6/ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "/opt/python/3.6.3/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:777)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/build/winecountry/quote-me/quote_me/tests.py", line 77, in setUp
self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 310, in execute
response = self.command_executor.execute(driver_command, params)
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 466, in execute
return self._request(command_info[0], url, body=data)
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 528, in _request
resp = opener.open(request, timeout=self._timeout)
File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:777)>
错误将我指向tests.py
文件中的第77行,即
self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)
这完全基于code from Travis,您可以看到我们的.travis.yml
。
def setUp(self):
if "TRAVIS" in environ:
username = environ["SAUCE_USERNAME"]
access_key = environ["SAUCE_ACCESS_KEY"]
capabilities = {}
capabilities["tunnel-identifier"] = environ["TRAVIS_JOB_NUMBER"]
hub_url = "%s:%s@localhost:4445" % (username, access_key)
capabilities["build"] = environ["TRAVIS_BUILD_NUMBER"]
capabilities["tags"] = [environ["TRAVIS_PYTHON_VERSION"], "CI"]
self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)
else:
self.selenium = webdriver.Safari()
super(FunctionalTestCase, self).setUp()
似乎是SSL证书问题,所以我调查了no_ssl_bump_domains
option但似乎没有帮助。还认为某些东西可能不稳定,因为我们使用的是Django manage.py runserver
命令。
如果您需要其他信息,请告诉我们,我们非常感谢您的帮助!
答案 0 :(得分:1)
通过更改
来解决此问题self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)
到
self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="http://%s/wd/hub" % hub_url)
如果您错过了,我们将command_executor
更改为使用http
而不是https
。
答案 1 :(得分:0)
错误确实给了我们一个提示:
File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
似乎确实是 encoding
问题。但是当您使用 Travis CI
时,我建议您更改参数的位置,原因如下:
根据文档,selenium.webdriver.remote.webdriver的WebDriver implementation
如下:
class selenium.webdriver.remote.webdriver.WebDriver(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False, file_detector=None, options=None)
根据你的代码块:
self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)
您可能正在尝试:
self.selenium = webdriver.Remote(command_executor="https://%s/wd/hub" % hub_url, desired_capabilities=capabilities)
注意:虽然我们没有接触过
desired_capabilities