Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Memory usage history from chromedriver using selenium

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.

like image 669
Joelle Boulet Avatar asked Mar 21 '23 20:03

Joelle Boulet


1 Answers

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.

like image 146
sjethvani Avatar answered Mar 24 '23 09:03

sjethvani