Selenium remotewebdriver与python-性能日志记录? [英] selenium remotewebdriver with python - performance logging?

查看:493
本文介绍了Selenium remotewebdriver与python-性能日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从远程Webdriver实例取回一些性能日志信息.我正在使用Python Selenium绑定.

据我所见,这是我应该能够得到的信息.认为它可能仅适用于ChromeDriver.我目前正在使用FireFox,但是如果得到我想要的信息,可以轻松切换.

但是,我是Python的新手(但是正在学习!),有关Python功能字典(用于性能日志记录)的文档似乎有点受限制(或者今天早上我的google-fu很弱)./p>

我发现了以下内容:

DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable("performance", Level.INFO);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
driver = new RemoteWebDriver("http://localhost:9515", caps);

它看起来应该可以满足我的需求.但这是Java.我不太确定如何将其转换为Python.假设有可能.

有什么想法吗?

解决方案

万一有人想知道,这似乎对我有用:

(假设您正在使用硒遥控器)

url = 'http://remote instance IP:PORT/wd/hub'
descaps = {'browserName': 'chrome', 'loggingPrefs': {'performance': 'INFO'}}

driver = webdriver.Remote(command_executor=url, desired_capabilities=descaps)

driver.command_executor._commands.update({'getAvailableLogTypes': 
                        ('GET', '/session/sessionId/log/types'), 
                        {'getLog': ('POST', '/session/$sessionId/log')})

getlog = driver.execute('getLog', {'type': 'performance'})['value']

(在添加的两个命令"getAvailableLogTypes"和"getLog"中,您只会在上面的代码片段中看到前者.后者只是返回远程会话中可用日志类型的列表.)

现在我需要做的就是解释它....

I'm trying to get back some performance log info from a remote webdriver instance. I'm using the Python Selenium bindings.

From what I can see, this is information I should be able to get back. Think it may only be available with ChromeDriver. I'm currently using FireFox but can easily switch over if it gets the info I want.

However, I'm new to Python (but learning!) and documentation around the capabilities dictionaries (when used for performance logging) for Python seems to be a bit limited (or my google-fu is weak this morning).

I've found the following:

DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable("performance", Level.INFO);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
driver = new RemoteWebDriver("http://localhost:9515", caps);

Which looks like it should do what I need. But it's Java. I'm not quite sure how I'd go about converting this to Python. Assuming it's possible.

Any ideas?

解决方案

In case anyone is wondering, this seems to do the trick for me:

(Assuming you're using selenium remote)

url = 'http://remote instance IP:PORT/wd/hub'
descaps = {'browserName': 'chrome', 'loggingPrefs': {'performance': 'INFO'}}

driver = webdriver.Remote(command_executor=url, desired_capabilities=descaps)

driver.command_executor._commands.update({'getAvailableLogTypes': 
                        ('GET', '/session/sessionId/log/types'), 
                        {'getLog': ('POST', '/session/$sessionId/log')})

getlog = driver.execute('getLog', {'type': 'performance'})['value']

(Of the two added commands 'getAvailableLogTypes' and 'getLog' - you only see the former in the above code snippet. The latter simply returns a list of the available log types on your remote session.)

Now all I need to do is interpret it ....

这篇关于Selenium remotewebdriver与python-性能日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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