【问题标题】:Running selenium test in Docker在 Docker 中运行 selenium 测试
【发布时间】:2019-09-17 09:41:43
【问题描述】:

我编写了一个 selenium 脚本,当我使用 cmd 启动它时运行良好。

我现在想在 docker 中执行脚本,以便可以轻松地从任何机器上一键启动。

我用基础镜像FROM selenium/standalone-chrome-debug写了一个Dockerfile

我像这样更改了我的脚本:

driver = webdriver.Remote("http://127.0.0.1:4444/wd/hub", DesiredCapabilities.CHROME)
driver.maximize_window()
driver.get("www.google.com")

但是当我启动它时,出现以下错误:

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=4444): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd11b9e3b90>: Failed to establish a new connection: [Errno 111] Connection refused',))

我是 docker 和 selenium 的新手,所以我可能忘记了一些东西。

【问题讨论】:

  • 您是否在 docker run 命令中提供了端口 4444

标签: python selenium docker


【解决方案1】:

您正在传递本地 IP 和本地端口号

http://127.0.0.1:4444 - 你的 IP 是本地和本地端口

您需要确定您的 selenium hub docker ipport 在同一 VM 上运行的哪个集线器并更新您的以下行:

driver = webdriver.Remote("http://127.0.0.1:4444/wd/hub", DesiredCapabilities.CHROME)

【讨论】:

  • 感谢您的回复,我设法让它工作,确实我错过了 selenium hub 步骤
猜你喜欢
  • 2015-12-01
  • 2020-04-22
  • 1970-01-01
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
  • 2018-12-13
  • 2012-06-21
  • 1970-01-01
相关资源
最近更新 更多