简体   繁体   English

带有 Selenium 的 StaticLiveServerTestCase:ERR_CONNECTION_REFUSED

[英]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 很可能会导致连接被拒绝错误:

  1. No server or service is active at 8000 port 8000 端口上没有服务器或服务处于活动状态
  2. Allowed origin setting is not allowing the connection, though this is entirely dependent on the settings.允许的来源设置不允许连接,尽管这完全取决于设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django:ERR_CONNECTION_REFUSED - Django: ERR_CONNECTION_REFUSED 错误选项 net::ERR_CONNECTION_REFUSED - Error OPTIONS net::ERR_CONNECTION_REFUSED 在 Gitlab CI 中为 Django 项目运行 Selenium 测试:ERR_CONNECTION_REFUSED on get live_server_url - Run Selenium tests for Django project in Gitlab CI : ERR_CONNECTION_REFUSED on get live_server_url 使用Heroku问题ERR_CONNECTION_REFUSED部署django - Deploy django with Heroku issue, ERR_CONNECTION_REFUSED 浏览器中的 Ray Dashboard 错误“ERR_CONNECTION_REFUSED” - Ray Dashboard error in the browser “ERR_CONNECTION_REFUSED” 谷歌驱动器 API OAuth 2.0:ERR_CONNECTION_REFUSED - Google Drive API OAuth 2.0: ERR_CONNECTION_REFUSED 无法获取“图像”.net::ERR_CONNECTION_REFUSED (Gitpod) - Cannot get "images" net::ERR_CONNECTION_REFUSED (Gitpod) 无法访问 Locust WebInterface“ERR_CONNECTION_REFUSED” - Can't reach Locust WebInterface "ERR_CONNECTION_REFUSED" 使用 Eclipse Pydev 打开 dtale 时浏览器上的 ERR_CONNECTION_REFUSED - ERR_CONNECTION_REFUSED on browser when opening dtale with Eclipse Pydev API 从 localhost 正常,但 Ajax 失败 - ERR_CONNECTION_REFUSED - API ok from localhost but failed with Ajax - ERR_CONNECTION_REFUSED
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM