在Docker上将DevTools功能与Selenium Grid结合使用



我设法在本地使用Selenium 4中的DevTools功能,但当我尝试在Selenium Grid上使用它时,它没有起作用。

为了调查它,我使用docker compose安装了一个带有一个Chrome节点的本地网格,但我得到了相同的错误:

OpenQA.Selenium.WebDriverException : Unexpected error creating WebSocket DevTools session.
----> System.Net.WebSockets.WebSocketException : Unable to connect to the remote server
----> System.Net.Http.HttpRequestException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (172.18.0.3:4444)
----> System.Net.Sockets.SocketException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

其中172.18.0.3是chrome节点容器的私有IP。

我想主要原因是我无法从主机访问该IP,这可能是一个docker配置问题,我不是这方面的专家。但这并不是唯一的问题。

使用调试器,我能够跟踪驱动程序是否尝试使用此地址,这是因为在创建后从驱动程序返回的以下功能:"se:cdp": "ws://172.18.0.3:4444/session/2c519f679e1060cdc926ca74e63e222f/se/cdp"。然后我调整了这个值(在调试器中,在尝试创建到DevTools协议的连接之前(,使用localhost而不是私有IP,然后我得到了以下错误:IOException: The response ended prematurely.

为了通过Selenium Grid(和docker(使用Selenium的DevTools功能,我需要做什么?

- SE_NODE_GRID_URL=http://localhost:4444/环境添加到"铬";dockercomposeyaml文件中的容器解决了这个问题。

如果要从主机外部访问网格,请写入机器的IP或名称,而不是localhost

最新更新