我正在通过“遵守测试山羊书”学习 TDD,但我正在尝试使用 Django 3。
如果有人知道的话,我在第6章。
我的代码是:
class VisitorTest(LiveServerTestCase):
def setUp(self):
self.browser = webdriver.Chrome()
self.browser.implicitly_wait(2)
def tearDown(self):
self.browser.quit()
def test_starting(self):
print(self.live_server_url)
self.browser.get(self.live_server_url)
Run Code Online (Sandbox Code Playgroud)
在控制台我得到
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
DevTools listening on ws://127.0.0.1:52187/devtools/browser/e9a03a04-819e-40a3-a0e4-bd4133d8f6cb
http://localhost:52180
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52204)
----------------------------------------
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52202)
Exception happened during processing of request from ('127.0.0.1', 52203)
Traceback (most recent call last):
Traceback (most recent call last): …Run Code Online (Sandbox Code Playgroud) 我正在使用Django收到此错误
RuntimeError: Failed to shutdown the live test server in 2 seconds. The server might be stuck or generating a slow response.
Run Code Online (Sandbox Code Playgroud)
我想在我的网站上的菜单上运行一个简单的测试.菜单采用手风琴风格(向下滚动到概述菜单下的示例.手风琴是Demo中的东西,根据您点击它们的方式菜单出现和消失:http://docs.jquery.com/UI/手风琴#概述)
当其中一个菜单打开时,会出现一个用于搜索的文本框.我要做的是按下该按钮,然后输入一些值并单击"确定"以查看搜索结果.
码
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 …Run Code Online (Sandbox Code Playgroud)