I created a Selenium Grid proxy, I want to log every command done, the problem is I can't find a way to get the response of the command for example after "GetTitle" command I want to get the "Title" returned.
1 Answers
Where do you want this logging to be done ? If you attempt at logging this at the Custom Proxy, then these logs would be available only on the machine that runs the hub. Is that what you want ? If yes, then here's how you should be doing it :
Within an overloaded variant of org.openqa.grid.internal.listeners.CommandListener#afterCommand
(this method should be available in your DefaultRemoteProxy
extension object that you are building), extract this information from within the javax.servlet.http.HttpServletRequest
by reading its entity value and then translating that into a proper payload.
Here's how the afterCommand()
(or) beforeCommand()
method from your customized version of org.openqa.grid.selenium.proxy.DefaultRemoteProxy
can look like:
org.openqa.grid.web.servlet.handler.SeleniumBasedResponse ar = new org.openqa.grid.web.servlet.handler.SeleniumBasedResponse(response);
if (ar.getForwardedContent() != null) {
System.err.println("Content" + ar.getForwardedContent());
}
If that's not what you want, then you should be looking at leveraging the EventFiringWebDriver
. Take a look at the below blogs to learn how to work with the EventFiringWebDriver
. The EventFiringWebDriver
does not require customization at the Grid side, it just needs you to make use of the EventFiringWebDriver
which would wrap within it an existing RemoteWebDriver
object and the listeners you inject to it will help you get this.
- http://darrellgrainger.blogspot.in/2011/02/generating-screen-capture-on-exception.html
- https://rationaleemotions.wordpress.com/2015/04/18/eavesdropping-into-webdriver/ (This is my blog) Here I talk about not even using
EventFiringWebDriver
but instead work with a decoratedCommandExecutor
which would log all these information for you.

- 14,121
- 6
- 34
- 66
-
I want to do it in a custom proxy. I have no problem with the request (which have the command type: click, url ..) but I can't get the response of that command, for example for getTitle command I want to access to the "title" returned. – Elheni Mokhles Aug 03 '17 at 09:16
-
@ElheniMokhles - I have updated my answer to show you code snippet of how to get this done. – Krishnan Mahadevan Aug 03 '17 at 13:35
-
I always get null when executing getForwardedContent() (both in beforeCommand and afteCommand) – Elheni Mokhles Aug 04 '17 at 14:18