【问题标题】:Django, Firewalls, Selenium, [Errno 10061], and implicitly_wait()Django、防火墙、Selenium、[Errno 10061] 和implicitly_wait()
【发布时间】:2016-02-22 15:37:23
【问题描述】:

所以,我对这个很好奇。

我一直在尝试使用 Django 进行 TDD,并从 Harry J.W. Percival的书,如下:

from selenium import webdriver
import unittest

class NewVisitorTest(unittest.TestCase):

    def setUp(self):
        self.browser = webdriver.Chrome()

    def tearDown(self):
        self.browser.quit()


    def test_can_start_list_and_retrieve_later(self):
        self.browser.get('http://localhost:8000')
        self.browser.implicitly_wait(3)

        self.assertIn('Django', self.browser.title)

看起来很简单。 除了我得到这个失败的测试:
error: [Errno 10061] No connection could be made because the target machine actively refused it

所以我相信我已经安装了某种防火墙(如果您能指导我,我将不胜感激)。然而,最奇怪的是以下内容: 但是,如果我在省略这一行的情况下运行脚本:self.browser.implicitly_wait(3)

测试奇怪地通过了。

当我没有通过测试时,Django 会说:

Not Found: /favicon.ico
[22/Feb/2016 09:34:38] "GET /favicon.ico HTTP/1.1" 404 1940

如果这有任何相关性:
操作系统是 Windows 10 IDE 是 PyCharm 社区(所以 Django 在 powershell 中运行) 测试框架是 Unittest.py

【问题讨论】:

    标签: python django selenium firewall


    【解决方案1】:

    Chrome 需要与您机器上安装的 Chrome 版本相匹配的特定驱动程序:

    self.browser = webdriver.Chrome("/path/to/chromedriver")
    

    https://sites.google.com/a/chromium.org/chromedriver/downloads下载chromedrive并将其复制到“/path/to/chromedriver”

    注意:对于 Firefox,可以使用 webdriver.Firefox()

    【讨论】:

    • 我有最新版本的 Chrome 和 chromedriver.exe(在 Django 项目的目录中)。我仍然收到错误消息。据我所知,不匹配也不能解释为什么“implicitly_waits()”决定测试是通过还是失败。也许它与另一个错误有关,即当我尝试向 Django 应用程序添加测试时,我得到了这个:ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
    • 这很正常。简单的等待解决了很多 Selenium,否则很难解释问题。等待是我第一次解决 Selenium 问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    • 2012-12-26
    • 2014-07-20
    相关资源
    最近更新 更多