Chrome Dev Tools API & Selenium WebDriver

11k views Asked by At

I am experimenting with Selenium Web Driver for automating my browser integration tests. I see that Chrome Dev Tools comes with a console API for invoking certain dev tool functions from inside JavaScript.

Ideally, from inside my Java/JUnit integration test, I could start the Chrome Dev Tool memory profiler (and perhaps some other tools), run my WebDriver tests (instantiating a Chrome browser instance, manipulating DOM elements, etc.), and then stop the profiler, then inspect the profiler's results to see if there are any memory leaks.

Is this concept even feasible or am I way out to lunch? Why/why not?

It seems like the API already has a console.profile() to start a profiling session, and a console.profileEnd(). So in theory I could have WebDriver invoke these two methods and run tests in between them.

I think the missing link is then programmatically interacting with the results of the profiling session...

2

There are 2 answers

1
loislo On

Chrome DevTools has two parts, front-end with UI and back-end in the native code of the renderer. These parts work with each other via protocol. The protocol is described in the protocol.js file

Chrome can work in remote debugging mode when it exposes tcp socket that can be used for interacting with the backend part of DevTools. This feature is actively used in Chrome browser Telemetry toolset

This toolset was written in python and we keep it in sync with the current version of the protocol. The toolset has the code for working with heap profiler part and other parts of the DevTools.

0
tomasdev On

You can actually use the debugger protocol as mentioned by @loislo above – you might find more useful the link https://developer.chrome.com/devtools/docs/debugger-protocol

Just add the flag when opening Chrome and remote-debug it! :)