1

I want to obtain logs generated by webdriver client bindings when a command is executed. Basically, I want the log representation of JSON wire protocol communication that happens between the client and the driver.

I tried doing that for Webdriver java client for ChromeDriver but that doesn't help.

System.setProperty("webdriver.chrome.driver","path-to-driver.exe");

DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.CLIENT,Level.ALL);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
ChromeOptions options = new ChromeOptions();
options.merge(caps);

WebDriver driver = new ChromeDriver(options);
System.out.println(driver.manage().logs().getAvailableLogTypes());

Output: enter image description here If you see the console output it says: "Ignoring unrecognized log type: client"

But driver.manage().logs().getAvailableLogTypes() does include client. Any help?

Related question: Monitoring JSON wire protocol logs

Abhijeet Vaikar
  • 1,578
  • 4
  • 27
  • 50

2 Answers2

0

To obtain WebDriver client logs (JSON wire communication) for chromedriver.exe we can configure the logfile and the type_of_logging as follows:

System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
System.setProperty("webdriver.chrome.logfile", "C:\\Utility\\BrowserDrivers\\chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.co.in");
driver.findElement(By.name("q"));
driver.quit();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks. Will try this soon and comment on the results. – Abhijeet Vaikar Nov 06 '17 at 12:19
  • Sorry but this did not help. It gave me all the driver logs which do not have JSON wire communication requests being sent from the client. – Abhijeet Vaikar Nov 11 '17 at 09:27
  • 1
    @Abhijeet Vaikar: The chromedriver.log will contain all the requests and responses both: Example of request: [13.179][INFO]: COMMAND GetElementText { "id": "0.8984444413515806-1" } and that of response is [13.251][INFO]: RESPONSE GetElementText "" – virusrocks Nov 12 '17 at 16:21
  • @virusrocks Yeah, that's the point. I think OP overstepped the log messages in the log file. – undetected Selenium Nov 12 '17 at 16:36
  • Nope. That is not what I am looking for. I am looking for the exact representation of the JSON wire protocol request that is sent by the client binding. Basically information about the wire end-point that was called, HTTP method used, request body (JSON) sent if it's a POST. The log output you shared is not that. I have seen this happening if you use an external logging library like Log4J but I don't want to get there yet. check this: https://w3c.github.io/webdriver/webdriver-spec.html#list-of-endpoints https://github.com/SeleniumHQ/selenium/wiki/Logging – Abhijeet Vaikar Nov 13 '17 at 04:15
  • Moreover if we have to set chromedriver to print it's logs into a log file, what is the point of using LoggingPreferences & setting log type to client? – Abhijeet Vaikar Nov 13 '17 at 04:32
0

This can be done easily by pointing your Java IDE to a proxy server and than capturing the entire http traffic between the IDE and proxy server. You can have some rules in the proxy to just filter the traffic related to JSON wire protocol.

The proxy server choices could be Browsermob, CharlesProxy or Fiddler.

Another option is:

Selenium Java bindings internally uses Apache HTTP client to send these json wire protocol requests and if you are using sl4j /log4j logger than in the log4j.properties file you can have this line:

log4j.logger.org.apache.http.wire=DEBUG

It will enable all the debug logging which is generated by apache http client and then you will start seeing all the network traffic exchanged between the selenium java client and chromedriver server. Here is the log generated for me for driver.findElement() command :

https://gist.github.com/sahajamit/6a54d8841a0db063c515e2460af260c1

I have just gone through their source code and found they are not at all logging these wire protocol interactions in selenium code. You can see the following java method: https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/remote/http/AbstractHttpCommandCodec.java#L215

The maximum information they are logging for a find element command is:

Executing: findElement [6461ed17770e6252b694ddecd8370093, findElement {using=id, value=gb_70}]

but if you want to know which wire protocol endpoint is used by this command called "findElement" then refer to this class file where they have defined this mapping.

defineCommand(FIND_ELEMENT, post("/session/:sessionId/element"));

https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/remote/http/AbstractHttpCommandCodec.java#L159

Amit Rawat
  • 31
  • 2
  • Did you try doing this for a local instance of WebDriver? I tried too many times figuring out if I can inspect all the wire requests going from webdriver client to the driver instance, but it didn't work at all. I tried it with Fiddler. It will probably help only if you are running driver on a remote machine. – Abhijeet Vaikar Nov 12 '17 at 15:43
  • Selenium Java bindings internally uses Apache HTTP client to send these json wire protocol requests and if you are using sl4j /log4j logger than in the log4j.properties file you can have this line: log4j.logger.org.apache.http.wire=DEBUG It will enable all the debug logging which is generated by apache http client and then you will start seeing all the network traffic exchanged between the selenium java client and chromedriver server. Here is the log generated for me for driver.findElement() command : https://gist.github.com/sahajamit/6a54d8841a0db063c515e2460af260c1 – Amit Rawat Nov 13 '17 at 06:12