Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium remotewebdriver with python - performance logging?

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?

like image 836
ColinMcC Avatar asked Aug 26 '14 11:08

ColinMcC


1 Answers

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

like image 112
ColinMcC Avatar answered Oct 04 '22 21:10

ColinMcC