Django和Selenium Web测试错误:[Errno 10054] [英] Django and Selenium Web testing error: [Errno 10054]

查看:148
本文介绍了Django和Selenium Web测试错误:[Errno 10054]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium网络驱动程序运行一些基本的功能网络测试,并且在我的两个功能网络测试案例中注意到了该错误。测试用例最终都通过了,但是我在控制台中得到了:

I'm running some basic functional web test with the Selenium web driver and I'm noticing this error in two of my functional web test cases. The test cases all pass at the end but I get this in the console:

Exception happened during processing of request from ('127.0.0.1', 1169)
    data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
Traceback (most recent call last):
  File "C:\dev\django-projects\barbwire\venv\lib\site-packages\django\test\testcases.py", line 981, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\Lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\Lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\dev\django-projects\barbwire\venv\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "C:\Python27\Lib\SocketServer.py", line 638, in __init__
    self.handle()
  File "C:\Python27\Lib\wsgiref\simple_server.py", line 116, in handle
    self.raw_requestline = self.rfile.readline()
  File "C:\Python27\Lib\socket.py", line 447, in readline
    data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
Traceback (most recent call last):
  File "C:\dev\django-projects\barbwire\venv\lib\site-packages\django\test\testcases.py", line 981, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\Lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\Lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\dev\django-projects\barbwire\venv\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "C:\Python27\Lib\SocketServer.py", line 638, in __init__
    self.handle()
  File "C:\Python27\Lib\wsgiref\simple_server.py", line 116, in handle
    self.raw_requestline = self.rfile.readline()
  File "C:\Python27\Lib\socket.py", line 447, in readline
    data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 1170)
----------------------------------------
Destroying test database for alias 'default'...

以下是其中一个测试用例的示例:

Here's an example of one of the test cases:

def test_can_join_main_site(self):
    self.browser.get(self.live_server_url)
    self.browser.find_element_by_link_text('Register').click()
    time.sleep(5)
    self.browser.find_element_by_name('submit').click()
    time.sleep(5)

它运行完成,但转储上述异常。这个想法是测试一个简单的注册页面。单击提交按钮后,页面会重新显示并提示用户填写其他表单字段。正如预期的那样,一切似乎都可以正常工作,但是为什么会出现错误?我错过了什么吗?

It runs to completion but dumps the above exception. The idea is to test a simple registration page. After clicking the submit button the page re-displays and prompts the user to fill out additional form fields. As expected and everything appears to work correctly but why the errors? Am I missing something?

推荐答案

用127.0.0.1替换 localhost 确实不适用于我,而添加 sleep 只会减慢测试速度。在退出浏览器之前,我可以通过调用refresh来摆脱错误:

Replacing localhost with 127.0.0.1 did not work for me, and adding sleep just slows the test down. I was able to get rid of the error by calling refresh before quitting the browser:

from selenium import webdriver
browser = webdriver.Firefox()
# do stuff with browser
browser.refresh()
browser.quit()

在我来说,这是在< link> < script>中加载静态文件; 引起问题的标签。但是当我在退出前添加 refresh 时,它消失了。

In my case it was the loading of static files in <link> and <script> tags that was causing the problem. But it went away when I added refresh before quitting.

这篇关于Django和Selenium Web测试错误:[Errno 10054]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆