Home > Back-end >  Using DevTools features with Selenium Grid on Docker
Using DevTools features with Selenium Grid on Docker

Time:10-11

I managed to work with DevTools features in Selenium 4 locally, but when I tried to use it on Selenium Grid, it didn't work.

In order to investigate it, I installed a local grid with one Chrome node using docker-compose and I got the same error:

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.

Where 172.18.0.3 is the private IP of chrome-node container.

I guess that the main reason is that I don't have access to that IP from the host, and that's probably a docker configuration matter, on which I'm not an expert. But that wasn't the only problem.

Using the debugger, I was able to track that the driver tries to use this address due to the following capability that is returned from the driver after creation: "se:cdp": "ws://172.18.0.3:4444/session/2c519f679e1060cdc926ca74e63e222f/se/cdp". I then tweaked this value (in the debugger, before trying to create the connection to the DevTools protocol) to use localhost instead of the private IP, and then I got the following error: IOException: The response ended prematurely..

What do I need to do in order to use the DevTools features of Selenium through Selenium Grid (and docker)?

CodePudding user response:

Adding - SE_NODE_GRID_URL=http://localhost:4444/ environment to the "chrome" container in the docker-compose yaml file solves the problem.

If you want to access the grid from outside of the host, instead of localhost write the IP or name of the machine.

  • Related