Monitoring JSON wire protocol logs

0
0

According to the selenium documentation, interactions between the webdriver client and a browser is done via JSON Wire Protocol. Basically the client, written in python, ruby, java whatever, sends JSON messages to the web browser and the web browser responds with JSON too.

Is there a way to view/catch/log these JSON messages while running a selenium test?

For example (in Python):

from selenium import webdriver
driver
= webdriver.Chrome()
driver
.get('http://google.com')
driver
.close()

I want to see what JSON messages are going between the python selenium webdriver client and a browser when I instantiate the driver (in this case Chrome): webdriver.Chrome(), when I’m getting a page: driver.get('http://google.com') and when I’m closing it: driver.close().

FYI, in the #SFSE: Stripping Down Remote WebDriver tutorial, it is done via capturing the network traffic between the local machine where the script is running and the remote selenium server.

I’m tagging the question as Python specific, but really would be happy with any pointers.

  • You must to post comments
0
0

When you use Chrome you can direct the chromedriver instance that will drive Chrome to log more information than what is available through the logging package. This information includes the commands sent to the browser and the responses it gets. Here’s an example:

from selenium import webdriver
driver
= webdriver.Chrome(service_log_path="/tmp/log")
driver
.get("http://www.google.com")
driver
.find_element_by_css_selector("input")
driver
.quit()

The code above will output the log to /tmp/log. The part of the log that corresponds to the find_element_... call looks like this:

[2.389][INFO]: COMMAND FindElement {
"sessionId": "b6707ee92a3261e1dc33a53514490663",
"using": "css selector",
"value": "input"
}
[2.389][INFO]: Waiting for pending navigations...
[2.389][INFO]: Done waiting for pending navigations
[2.398][INFO]: Waiting for pending navigations...
[2.398][INFO]: Done waiting for pending navigations
[2.398][INFO]: RESPONSE FindElement {
"ELEMENT": "0.3367185448296368-1"
}

As far as I know, the commands and responses faithfully represent what is going on between the client and the server. I’ve submitted bug reports and fixes to the Selenium project on the basis of what I saw in these logs.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website