我正在使用 docker、selenium 和 Django。
我刚刚意识到我正在对我的生产数据库进行测试;而我想在 StaticLiveServerTestCase
自生成的数据库上进行测试。
我试着关注 that tutorial
@override_settings(ALLOWED_HOSTS=['*'])
class BaseTestCase(StaticLiveServerTestCase):
host = '0.0.0.0'
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.host = socket.gethostbyname(socket.gethostname())
cls.selenium = webdriver.Remote(
command_executor='http://hub:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME,
)
cls.selenium.implicitly_wait(5)
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
class MyTest(BaseTestCase):
def test_simple(self):
self.selenium.get(self.live_server_url)
我尝试连接到 chrome-hub 时没有错误,但是当我尝试打印我的 page_source 时,我不在我的 django 应用程序上,而是在 chrome 错误消息上。这是一部分:
<div class="error-code" jscontent="errorCode" jstcache="7">ERR_CONNECTION_REFUSED</div>
我正在使用 docker-compose 1.Selenium.yml:
chrome:
image: selenium/node-chrome:3.11.0-dysprosium
volumes:
- /dev/shm:/dev/shm
links:
- hub
environment:
HUB_HOST: hub
HUB_PORT: '4444'
hub:
image: selenium/hub:3.11.0-dysprosium
ports:
- "4444:4444"
expose:
- "4444"
app:
links:
- hub
我想我在 docker-compose 文件中做错了什么,但我没弄清楚是什么。
提前致谢!
PS : live_server_url
= http://localhost:8081
最佳答案
关于python - Django : Connection refused to live_server_url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50601185/