Chrome remote debugging in a seleniumgrid
D

1

0

Im running a selenium-grid with several chrome instances. The selenium grid are 2 machines(windows) with several nodes. The tests are executed from another machine which connects to the grid. To be able to use the features of remote debugging, i need to connect from the executing machine(which can read the sessions host and the drivers debugUrl) to the other machines and finally the chrome instances.

But chrome rejects anything else than localhost.

I can only find solutions, where people tunnel or port forwarding, which is perhaps ok, when there is only a single instance. In a grid i don't have static ports or static rules to provide static forwarding.

In my scenario the grid is build up automated and not an ever running system.

Has anybody a hint how to solve this?

Distrustful answered 2/2, 2018 at 14:49 Comment(2)
Possible duplicate of Chrome remote debugging doesn't work with IPSuccubus
The problem is that i have a grid and the solutions of this question with tunnels, are not fitting. I thought my question was clear about it.Distrustful
D
-1

Since i found a solution by myself i want to share. I will only post parts of code to give the hints and not the full code since its to much work here, but for an experienced developer this should be enough.

To be able to address the right browser and access its remote-debug websocket i implemented a custom servlet for my nodes.

First the servlet:

public class DebugServlet extends RegistryBasedServlet

being registered through the node.json like

"servlets" :["com.....ui.util.DebugServlet"],

To access the node(on the right machine) i ask the selenium session for it like:

"http://" + hubHost + ":" + hubPort + "/grid/api/testsession?session=" + sessionId

where the "sessionid" can be retrieved from chromedriver.

From the returned json we can extract the node info of the session, here we need the url.

url = JSONUtil.get(response.getBody(), "proxyId")

No we can call the servlet of the correct host and give in the websocket url for the browser and whatever data is needed. In my example to add a default network-header for BasicAuth.

url+ "/extra/DebugServlet"

with the header in java(can also be parameters or other http provided possibilities)

new BasicHeader("BrowserUrl", webSocketDebuggerUrl), new BasicHeader("Name", name),
                new BasicHeader("Value", value)

In the servlet we extract now the data and open a websocket to the browser with the given url and make our calls.

In the servlet:

public static final String networkDebugging = "{\"id\": 1,\"method\": \"Network.enable\",\"params\": {\"maxTotalBufferSize\": 10000000,\"maxResourceBufferSize\": 5000000 }}";

public static final String addHeader = "{\"id\": 2,\"method\": \"Network.setExtraHTTPHeaders\",\"params\": { \"headers\": {\"${key}\": \"${value}\"}}}";


ws.connect();
ws.setAutoFlush(true);
ws.sendText(networkDebugging);

String payload = TemplateUtil.replace(addHeader, name, value);
ws.sendText(payload);
Distrustful answered 8/2, 2018 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.