2

I would like to track memory usage in a Protractor test by accessing the

window.performance.memory object.

I have added the necessary flag to to the protractor.conf.js by adding

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: ['enable-memory-info'],

And I can access the memory object via the above command. My question is how to access the window object from the protractor test itsself?

I have tried:

element(by.id('window')).then(function(win){
        theWindow = win;
        console.log("Set the window: " + theWindow);
        var mem = win.performance.memory;
        console.log("Memory: " + mem);

but this selector seems to be unavailable with this error:

NoSuchElementError: No element found using locator: By.id("window")

What options do I have in Protractor to access the browser window ? I have also tried the advice given here Access window object / browser scope from protractor, but had no success in getting the memory object.

Community
  • 1
  • 1
Carl
  • 1,266
  • 10
  • 20

1 Answers1

4

A slight modification to this post's code seems to do the trick:

function measurememory() {
    browser.driver.executeScript(function () {
        return window.performance.memory;
    }).then(function (result) {
        console.log("MemoryInfo: jsHeapSizeLimit : " + result.jsHeapSizeLimit);
        console.log("MemoryInfo: usedJSHeapSize : " + result.usedJSHeapSize);
        console.log("MemoryInfo: totalJSHeapSize : " + result.totalJSHeapSize);

    });
}
Community
  • 1
  • 1
Carl
  • 1,266
  • 10
  • 20