6

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

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

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

我发现了以下内容:

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。假设这是可能的。

有任何想法吗?

4

2 回答 2

8

如果有人想知道,这似乎对我有用:

(假设您使用的是硒遥控器)

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' - 您只能在上面的代码片段中看到前者。后者只是返回远程会话上可用日志类型的列表。)

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

于 2014-08-26T14:41:45.390 回答
-1

在玩了一段时间的 Chromedriver 日志后,我发现了一个更紧凑的解决方案,它可以在 Chrome 以外的浏览器上运行。

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

它为 Navigation Timing API ( https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html ) 添加了一个很好的包装器。提供更紧凑的数据集,并且更易于解释和使用。

它围绕标准 Selenium 放置的其他包装器实际上也相当不错!

于 2014-08-29T09:59:41.103 回答