RuntimeError:在2秒内无法关闭实时测试服务器。服务器可能卡住或产生缓慢的响应。 - Django [英] RuntimeError: Failed to shutdown the live test server in 2 seconds. The server might be stuck or generating a slow response. - Django
问题描述
RuntimeError:无法在2秒钟内关闭实时测试服务器。服务器可能卡住或产生缓慢的响应。
我试图在我的网站上的菜单上运行一个简单的测试。菜单是手风琴风格(向下滚动到概览菜单下的示例)手风琴是演示中的菜单,根据您点击它们,菜单出现并消失: http://docs.jquery.com/UI/Accordion#overview )
当其中一个菜单打开时,出现一个用于搜索的文本框。我想要做的是按该按钮,然后输入一些值,然后单击Enter去查看搜索结果。
代码
from django。从selenium.webdriver.common.keys导入键测试导入LiveServerTestCase
从selenium.webdriver.firefox.webdriver导入WebDriver
从selenium.webdriver.support.ui导入键
导入WebDriverWait
导入时间
class SeleniumTests(LiveServerTestCase):
fixtures = ['testData.json',]
@classmethod
def setUpClass(cls):
cls.driver = WebDriver()
super(SeleniumTests,cls).setUpClass()
@classmethod
def tearDownClass(cls):
super SeleniumTests,cls).tearDownClass()
cls.driver.quit()
def test_example(self):
#加载站点
self .driver.get('%s%s'%(self.live_server_url,'/ testingDB /'))
#find手风琴按钮
elem1 = self.driver.find_element_by_id(search_button)
#click it
elem1.click()
#等待一点手风琴装载
self.driver.implicitly_wait(5)
#也可以使用这个命令 - > time .sleep(1)
#find现在出现的元素
elem = self.driver.find_element_by_name(q)
#输入搜索查询并按enter键
elem.send_keys(selenium+ Keys.RETURN)
#assert加载一个新页面,在标题
中搜索assertsearchin self.driver.title
测试很棒,但Django给了我错误。如果我缩短时间太多,那么硒将无法找到搜索框,它声称
元素是目前不可见,所以可能不会与
不相互影响我不知道如何避免现场测试服务器错误。 (从 https://docs.djangoproject获取的Django信息。 com / en / dev / topics / testing /#django.test.LiveServerTestCase )
其他信息
这是菜单:
第1部分
然后点击搜索,下面出现约0.5秒。
第2部分
您所看到的错误与 SeleniumTests.tearDownClass(CLS)
。在该方法中,如果在调用 super(SeleniumTests,cls)之前调用
错误会消失。 cls.driver.quit()
.tearDownClass()
I am getting this error with Django
RuntimeError: Failed to shutdown the live test server in 2 seconds. The server might be stuck or generating a slow response.
I am trying to run a simple test on a menu on my website. The menu is in an accordion style (scroll down to Example under the overview menu. An accordion is the thing in the Demo, where menus appear and disappear according to how you click them: http://docs.jquery.com/UI/Accordion#overview)
When one of the menus open, a text box for searching is present. What I'm trying to do is to press that button, then enter some values and click 'Enter' to go see the search results.
CODE
from django.test import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import time
class SeleniumTests(LiveServerTestCase):
fixtures = ['testData.json',]
@classmethod
def setUpClass(cls):
cls.driver = WebDriver()
super(SeleniumTests, cls).setUpClass()
@classmethod
def tearDownClass(cls):
super(SeleniumTests, cls).tearDownClass()
cls.driver.quit()
def test_example(self):
#load the site
self.driver.get('%s%s' % (self.live_server_url, '/testingDB/'))
#find the accordion button
elem1 = self.driver.find_element_by_id("search_button")
#click it
elem1.click()
#wait a little bit so the accordion loads
self.driver.implicitly_wait(5)
#could've also used this command ->time.sleep(1)
#find the element that now appeared
elem = self.driver.find_element_by_name("q")
#enter the search query and press enter
elem.send_keys("selenium" + Keys.RETURN)
#assert that a new page loaded, with Search in the title
assert "Search" in self.driver.title
The test works great, but Django gives me the error. If I shorten the time too much, then selenium won't be able to find the search box, and it claims
Element is not currently visible and so may not be interacted with
I don't know how to avoid the live test server error. (Django information obtained from https://docs.djangoproject.com/en/dev/topics/testing/#django.test.LiveServerTestCase )
Additional Information
This is the menu:
Part 1
Then click 'Search' and the below appears in about 0.5 seconds.
Part 2
The error you are seeing is associated with the clean-up code found in SeleniumTests.tearDownClass(cls)
. Within that method, if you call cls.driver.quit()
before you call super(SeleniumTests, cls).tearDownClass()
the error will go away.
这篇关于RuntimeError:在2秒内无法关闭实时测试服务器。服务器可能卡住或产生缓慢的响应。 - Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!