python - 我们如何使用带有 Selenium 的 Django LiveServerTestCase 来测试 https url

标签 python django selenium https automated-tests

我们的端到端测试使用 Django 的 LiveServerTestCase 和 Selenium。到目前为止,我们只能在不安全的 URL 上运行这些。然而,我们使用的一些库(Square)要求页面在 https 上,即使在沙盒模式下也是如此。

当尝试连接到安全 url 时,Selenium/Chrome Webdriver 仅显示不支持标准 SSL 错误:

This site can’t provide a secure connection chezpierre.localtest.me sent an invalid response.
ERR_SSL_PROTOCOL_ERROR

有谁知道是否可以在 LiveServerTestCase 上启用 https?

如果没有,是否有人对此有解决方法?我试图避免在我们的构建盒上运行单独的 https 代理,但它似乎是唯一的方法。

最佳答案

经过快速研究,我发现这在旧代码票据建议的 Django 中是不可能的 https://code.djangoproject.com/ticket/25328

我还发现您可以设置一个隧道来绕过这个问题。然而,这适用于 Django 开发服务器。这有点棘手,所以我留下了指向帖子的链接,因为该方法相当长:

https://www.ianlewis.org/en/testing-https-djangos-development-server

How can I test https connections with Django as easily as I can non-https connections using 'runserver'?

备选方案 - 在我看来更好

还有一种使用外部包的更简单的方法。它为您提供开箱即用的支持 https 的 django 开发服务器。项目活跃并维护

https://github.com/teddziuba/django-sslserver

关于python - 我们如何使用带有 Selenium 的 Django LiveServerTestCase 来测试 https url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57187920/

相关文章:

java - 如何为现有驱动程序对象设置 Firefox 配置文件

python - 在 Selenium、Python 中查找下一个兄弟特定元素?

python - 我怎样才能只得到旋转矩形的四个角?

python - 如何将字段值从一个模型获取到另一个模型

python - Django Rest Framework 文档中不显示具有多个方法的多个嵌套资源

python - Django:将自定义管理器添加到 auth.User 时不创建迁移

string - 如何将 selenium webelements 转换为 python 中的字符串列表

python - 使用 ROI 找球 (Python/OpenCV)

python - 如何从 CSV 模块使用 Python 迭代器

python - 在 Python 中用 prettyprint 类包装 markdown 代码块