简体   繁体   English

selenium remotewebdriver与python - 性能记录?

[英]selenium remotewebdriver with python - performance logging?

I'm trying to get back some performance log info from a remote webdriver instance. 我正在尝试从远程webdriver实例获取一些性能日志信息。 I'm using the Python Selenium bindings. 我正在使用Python Selenium绑定。

From what I can see, this is information I should be able to get back. 从我所看到的,这是我应该能够获得的信息。 Think it may only be available with ChromeDriver. 认为它可能只适用于ChromeDriver。 I'm currently using FireFox but can easily switch over if it gets the info I want. 我目前正在使用FireFox,但如果它能获得我想要的信息,可以轻松切换。

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). 但是,我是Python的新手(但是学习!)和Python的功能词典(当用于性能记录时)的文档似乎有点受限(或者我的google-fu今天早上很弱)。

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. 但它是Java。 I'm not quite sure how I'd go about converting this to Python. 我不太确定如何将其转换为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.) (在两个添加的命令'getAvailableLogTypes'和'getLog'中 - 您只在上面的代码片段中看到前者。后者只返回远程会话中可用日志类型的列表。)

Now all I need to do is interpret it .... 现在我需要做的只是解释它....

After playing around with the Chromedriver log for a while, I found a more compact solution that works on browsers other than Chrome. 在使用Chromedriver日志一段时间之后,我发现了一个更紧凑的解决方案,适用于Chrome以外的浏览器。

This: https://pypi.python.org/pypi/seleniumwrapper 这个: https//pypi.python.org/pypi/seleniumwrapper

Which adds a nice wrapper round the Navigation Timing API ( https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html ). 这为Navigation Timing API添加了一个很好的包装器( https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html )。 Gives a far more compact set of data and is much easier to interpret and use. 提供更紧凑的数据集,更易于理解和使用。

The other wrappers it puts round standard Selenium are actually quite nice too! 它围绕标准Selenium的其他包装器实际上也很不错!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM