我有一个复杂的 python-selenium 测试套件来测试非公共网页。在该设置中,我需要获取如下所示的 webdriver:
self.driver = webdriver.Firefox(firefox_profile = profile, log_path = logfile)
Run Code Online (Sandbox Code Playgroud)
带有一些配置文件和日志路径。在大多数情况下,这行代码工作正常,但有时(5%或这种情况)我收到套接字超时错误:
File "/root/tests/usecase_tests/tools/basicsuite.py", line 213, in set_driver_firefox
self.driver = webdriver.Firefox(firefox_profile = profile, log_path = logfile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 309, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 460, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 484, in _request
resp = self._conn.getresponse()
File "/usr/lib/python2.7/httplib.py", line 1136, in getresponse
response.begin()
File "/usr/lib/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.7/httplib.py", line 409, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "/usr/lib/python2.7/socket.py", line 480, in readline
data = self._sock.recv(self._rbufsize)
timeout: timed out
Run Code Online (Sandbox Code Playgroud)
此错误的可能原因是什么?如何调试这个错误?如何解决?
该错误说明了一切:
File "/usr/lib/python2.7/socket.py", line 480, in readline
data = self._sock.recv(self._rbufsize)
timeout: timed out
Run Code Online (Sandbox Code Playgroud)
以下是事件发生的顺序:
最初错误发生在basicsuite.py文件中的以下行:
self.driver = webdriver.Firefox(firefox_profile = profile, log_path = logfile)
Run Code Online (Sandbox Code Playgroud)经过一系列检查后,最终调用了以下方法,但失败了:
def readinto(self, b):
"""Read up to len(b) bytes into the writable buffer *b* and return
the number of bytes read. If the socket is non-blocking and no bytes
are available, None is returned.
If *b* is non-empty, a 0 return value indicates that the connection
was shutdown at the other end.
"""
self._checkClosed()
self._checkReadable()
if self._timeout_occurred:
raise OSError("cannot read from timed out object")
while True:
try:
return self._sock.recv_into(b)
except timeout:
self._timeout_occurred = True
raise
except error as e:
if e.args[0] in _blocking_errnos:
return None
raise
Run Code Online (Sandbox Code Playgroud)程序错误出现在:
self._sock.recv(b) # where If *b* is non-empty, a 0 return value indicates that the connection was shutdown at the other end.
Run Code Online (Sandbox Code Playgroud)结论是,建立连接的尝试未成功,这意味着实例的初始化webdriver以及新Mozilla Firefox浏览器会话的进一步生成均未成功。
不可能得出timeout: timed out发生的真正原因。但您可以遵循以下一些最佳实践:
提供日志文件的完整名称以及logical location日志文件的名称(来自项目级别),如下所示:
self.driver = webdriver.Firefox(firefox_profile=profile, log_path='./Log/geckodriver.log')
Run Code Online (Sandbox Code Playgroud)始终quit()在tearDown()方法中使用,以便正确销毁webdriver和 两者。webclient
在启动之前Test Execution,请确保系统中Task Manager没有悬空的实例GeckoDriver或进程。Firefox
确保您使用的二进制版本JDK、Selenium、GeckoDriver、Mozilla Firefox Browser兼容。您可以在此 QA 中找到详细的讨论Selenium WebDriver 3.4.0 + geckodriver 0.18.0 + Firefox ?? - which combination works?
在执行.Project WorkspaceTest Suite
CCleaner定期使用工具来清除操作系统的杂务。
如果 的基本版本Firefox Browser太旧,请卸载Firefox Browser并Revo Uninstaller安装Moderate Scan最新GA-Released版本的Firefox Browser。
| 归档时间: |
|
| 查看次数: |
3307 次 |
| 最近记录: |