监控JSON Wire协议日志 [英] Monitoring JSON wire protocol logs

查看:228
本文介绍了监控JSON Wire协议日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据硒文档,Webdriver客户端和浏览器之间的交互是通过 JSON Wire Protocol JSON Wire Protocol .基本上,用python,ruby,java等语言编写的客户端将JSON消息发送到Web浏览器,并且Web浏览器也以JSON进行响应.

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.

是否有一种方法可以在运行硒测试时查看/捕获/记录这些JSON消息?

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

例如(在Python中):

For example (in Python):

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('http://google.com')

driver.close()

当我实例化驱动程序(在本例中为Chrome):webdriver.Chrome(),获取页面:driver.get('http://google.com')以及何时启动驱动器时,我想查看python selenium webdriver客户端和浏览器之间发生了什么JSON消息.我正在关闭它: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().

仅供参考,在 #SFSE:精简远程WebDriver 教程中,这是通过捕获网络流量来完成的在运行脚本的 local 计算机和 remote 硒服务器之间.

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.

我将问题标记为特定于Python,但实际上对任何指针都会感到满意.

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

推荐答案

使用Chrome时,您可以指示chromedriver实例,该实例将驱动Chrome记录比通过logging包提供的信息更多的信息.该信息包括发送到浏览器的命令及其获得的响应.这是一个示例:

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()

上面的代码会将日志输出到/tmp/log.日志中与find_element_...调用相对应的部分如下所示:

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"
}

据我所知,命令和响应忠实地代表了客户端和服务器之间发生的事情.根据我在这些日志中看到的内容,我已经提交了有关Selenium项目的错误报告和修复程序.

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.

这篇关于监控JSON Wire协议日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆