selenium remotewebdriver with python - performance logging?
Asked Answered
U

2

6

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?

Unfailing answered 26/8, 2014 at 11:29 Comment(1)
D'oh. 5 minutes after posting, I found this: gist.github.com/klepikov/5457750 .... which gives some sample Python code. So I'm off to play with that ....Unfailing
U
8

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 ....

Unfailing answered 26/8, 2014 at 14:41 Comment(2)
You can define the capabilities with caps = webdriver.DesiredCapabilities.CHROME.copy(); caps['loggingPrefs'] = {'performance': 'INFO'}; driver = webdriver.Remote(command_executor=url, desired_capabilities=capabilities)Concubinage
@ JorgeOrpinel I think your comment has a typo: desired_capabilities=caps)Conquian
U
-1

After playing around with the Chromedriver log for a while, I found a more compact solution that works on browsers other than Chrome.

This: 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). 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!

Unfailing answered 29/8, 2014 at 9:59 Comment(1)
Please elaborate. I don't actually see this adding anything helpful around the timing API.Denunciation

© 2022 - 2024 — McMap. All rights reserved.