[英]StaticLiveServerTestCase with Selenium: ERR_CONNECTION_REFUSED
I'm running the default snippet from the docs for testing with selenium but 'm using Chrome driver.我正在运行文档中的默认代码段以使用 selenium 进行测试,但我使用的是 Chrome 驱动程序。 When I run the tests using
python manage.py test
it can't connect to the server seems it won't start, throwing the error ::ERR_CONNECTION_REFUSED
.当我使用
python manage.py test
运行测试时,它无法连接到服务器,似乎无法启动,抛出错误::ERR_CONNECTION_REFUSED
。 Any ideas?有任何想法吗?
Here is the snippet:这是片段:
from django.test import LiveServerTestCase
from selenium import webdriver
class MySeleniumTests(LiveServerTestCase):
# fixtures = ['user-data.json']
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.selenium = webdriver.Chrome(executable_path='./chromedriver')
cls.selenium.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
def test_login(self):
self.selenium.get('http://localhost:8000/accounts/login')
Why is the url hard coded(localhost:8000) in test_login?为什么 url 在 test_login 中被硬编码(本地主机:8000)? Since you are using LiveServerTestCase, you would be able to access the server base URL with
self.live_server_url
.由于您使用的是 LiveServerTestCase,因此您可以使用 self.live_server_url 访问服务器库
self.live_server_url
。 This is also mentioned on the docs link you have added in the description.您在说明中添加的文档链接中也提到了这一点。 The connection refused error is most likely happening due to the hard-coded URL for one of the following reasons:
由于以下原因之一,硬编码 URL 很可能会导致连接被拒绝错误:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.