Question

I am using chromedriver to test a javascript webapp. How can I get the memory usage information (the kind of information shown on the "History" tab of the chrome dev tools) through chromedriver and selenium.

This strikes me that it should be possible since chromedriver uses chrome's devtools's debugging system to interact with and control chrome.

The language I'm currently using for selenium is java but if you can provide examples in any language that would be aprreciated.

Était-ce utile?

La solution

I did something like this in chrome for getting my application's javascript memory usage

Chrome driver should be opened with below chromeOptions.

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--enable-precise-memory-info"); // enabling this flag to get precise js heap memory info for chrome browser
        WebDriver driver = new RemoteWebDriver(new URL(localhost:4444+"/wd/hub"), chromeOptions);

& then using below logic , we can get JavaScript memory usage of chrome instance

  JavascriptExecutor executor = (JavascriptExecutor) driver;
  long value = (long) executor.executeScript("return window.performance.memory.usedJSHeapSize");
  long valueInMB = value / (1024 * 1024);

PS : I was able to find this only for chrome browser & not for firefox.

Autres conseils

As you mentioned in your comment, you cannot launch devTool when you are using Selenium.

However, there is an interesting discussion about retrieving memory usage (heap snapshot) via chrome API (javascript): https://code.google.com/p/chromium/issues/detail?id=448379. If Chromium dev team implement this, you can use Selenium to execute JavaScript to get heap snapshot.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top