简体   繁体   English

我们如何使用 Django LiveServerTestCase 和 Selenium 来测试 https url

[英]How can we use Django LiveServerTestCase with Selenium to test https urls

Our end-to-end tests use Django's LiveServerTestCase with Selenium.我们的端到端测试使用 Django 的 LiveServerTestCase 和 Selenium。 So far we have only been able to run these on insecure urls.到目前为止,我们只能在不安全的 url 上运行这些。 However, some of the libraries that we use (Square) require a page to be on https even in sandbox mode.但是,我们使用的一些库(Square)需要一个页面在 https 上,即使在沙盒模式下也是如此。

When attempting to connect to a secure url, Selenium/Chrome Webdriver simply shows the standard SSL not supported error:尝试连接到安全 url 时,Selenium/Chrome Webdriver 仅显示标准 SSL 不支持错误:

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

Does anyone know if it is possible to enable https on a LiveServerTestCase?有谁知道是否可以在 LiveServerTestCase 上启用 https?

If not, does anyone have a working workaround for this?如果没有,是否有人对此有解决方法? I'm trying to avoid running a separate https proxy on our build box, but it seems like it might be the only way.我试图避免在我们的构建框上运行单独的 https 代理,但这似乎是唯一的方法。

After quick research I found out that this is impossible in Django suggested by this old code ticket https://code.djangoproject.com/ticket/25328经过快速研究,我发现这在旧代码票https://code.djangoproject.com/ticket/25328建议的 Django 中是不可能的

I also found out that you could setup a tunnel to bypass this issue.我还发现你可以设置一个隧道来绕过这个问题。 However this applies to django development server.但是,这适用于 django 开发服务器。 This is kind of tricky so I am leaving links to posts as the method is rather long:这有点棘手,所以我留下了帖子的链接,因为方法很长:

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

or或者

How can I test https connections with Django as easily as I can non-https connections using 'runserver'? 如何像使用“runserver”进行非 https 连接一样轻松地测试与 Django 的 https 连接?

ALTERNATIVE - In my opinion better替代方案- 在我看来更好

There is also a simpler way using an external package.还有一种使用外部包的更简单的方法。 It gives you out of the box a https capable django development server.它为您提供了一个开箱即用的支持 https 的 django 开发服务器。 The project is active and maintained该项目处于活动状态并得到维护

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

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

相关问题 如何在Django中使用LiveServerTestCase和Selenium测试登录功能 - How to test login functionality using LiveServerTestCase and Selenium in Django 如何在没有HTTPS的情况下运行Django 1.6 LiveServerTestCase? - How to run Django 1.6 LiveServerTestCase without HTTPS? django selenium LiveServerTestCase - django selenium LiveServerTestCase Python django:如何使用django LiveServerTestCase调用selenium.set_speed() - Python django: How to call selenium.set_speed() with django LiveServerTestCase 尝试使用 LiveServerTestCase 测试 Flask 应用程序时出现“无法腌制本地对象‘LiveServerTestCase’”错误 - Getting a "Can't pickle local object 'LiveServerTestCase'" error when trying to use LiveServerTestCase to test Flask app Django 功能性 LiveServerTestCase - 使用 selenium 提交表单后,对象保存到非测试数据库 - Django functional LiveServerTestCase - After submitting form with selenium, objects save to non-test database 使用Django 1.11从Docker Selenium运行LiveServerTestCase - Run LiveServerTestCase from Docker Selenium with Django 1.11 Django LiveServerTestCase:在测试时禁用SSL - Django LiveServerTestCase: disable SSL at test-time 如何在 Django 中将 .format() 与 url 一起使用? - How can I use .format() with urls in Django? 强制Django在撤消时使用HTTPS URL - Force Django to use HTTPS URLs when reversing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM