我正在尝试运行位于我的自动化容器中的自动化GUI测试套件。
我单独下载了selenium-firefox映像,并作为容器运行在端口4444上。正在运行的
localhost:4444/wd/hub现在,我试图在我的自动化容器中运行测试套件,我使用下面的代码以无头模式运行,以达到robotframework测试套件中selenium的firefox版本。
Open Browser http://www.youtube.com headlessfirefox remote_url=http://localhost:4444/wd/hub当我从我的机器上运行我的测试套件时,这种方法工作得很好,当我在自动化容器中运行它时,它就失败了。
我的自动化容器是否可以到达selenium-firefox容器来使用浏览器?
错误:
C: 10: Open Chrome headless
/usr/local/lib/python3.6/site-packages/requests/__init__.py:91:
RequestsDependencyWarning: urllib3 (1.26.3) or chardet (3.0.4) doesn't
match a supported version!
RequestsDependencyWarning)
[ WARN ] Retrying (Retry(total=2, connect=None, read=None, redirect=None,
status=None)) after connection broken by
'NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f4a322440b8>: Failed to establish a
[ WARN ] Retrying (Retry(total=1, connect=None, read=None, redirect=None,
status=None)) after connection broken by
'NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f4a32244710>: Failed to establish a
new connection: [Errno 111] Connection refused',)': /wd/hub/session
[ WARN ] Retrying (Retry(total=0, connect=None, read=None, redirect=None,
status=None)) after connection broken by
'NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f4a32235710>: Failed to establish a
new connection: [Errno 111] Connection refused',)': /wd/hub/session
| FAIL |
MaxRetryError: HTTPConnectionPool(host='localhost', port=4444): Max
retries exceeded with url: /wd/hub/session (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f4a32235438>: Failed to establish a new connection: [Errno 111]
Connection refused',))任何帮助都是感激的
发布于 2021-03-12 10:00:55
您的容器被认为是一台不同的机器,网络方面的。启动selenium-firefox映像时,可能会将容器的端口4444与主机的端口4444链接起来。然后,当您在主机上请求localhost:4444时,它将链接到您的容器。
但是当您启动另一个容器时,localhost:4444意味着这个容器的端口4444!
您应该做的是使用embed机械对接器提供:当您创建一个容器时,它有一个名称(您可以指定)。Docker在默认的停靠网络上为其提供内部ip,但不将容器名称与该ip关联。为了能够在您的urls中使用容器名作为域名,您需要创建一个新的网络,然后它将使用嵌入码头dns并将其自己的名称作为别名。
这就是为什么Vova的答案是有效的:docker默认为您的容器创建一个网络,这意味着它们会自动获得别名。我习惯于使用网络和/或写作,以至于忽略了一个事实,即在默认的码头网络中,别名不是自动的。
您应该只为这些容器创建特定的桥接网络:docker network create selenium-net --driver bridge
然后是docker run -p 4444:4444 --name selenium --network selenium-net selenium/standalone-firefox:latest
在运行其他容器时,还应该将它们添加到selenium-net网络中。
另一种方法是将您已经拥有的容器连接到网络上:假设我让容器selenium和testsuite运行(或已经存在),我将运行docker network connect selenium-net selenium和docker network connect selenium-net testsuite将它们放到网络中。当您这样做时,您可以指定--alias选项,如果您想在码头网络上给他们一个粒子化名/域。
发布于 2021-03-12 09:59:33
您需要使用要创建的所有容器创建docker-compose.yml文件:
version: '3.8'
services:
chrome:
image: selenium/standalone-chrome:85.0
hostname: chrome
ports:
- "4444:4444"
e2e-tests:
build: .
depends_on:
- chrome并在容器中使用主机名“chrome”,使用它的方式如下:
cls.driver = webdriver.Remote(command_executor='http://chrome:4444/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)https://stackoverflow.com/questions/66597600
复制相似问题