Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most efficient way to track browser memory consumed by the execution of a Protractor test?

The idea is to:

  1. Measure usedJSHeapSize before starting the test.
  2. Measure usedJSHeapSize after completing the test.
  3. Comparing values from 1 and 2 and if the size increases above a defined threshold, then fail the scenario.

So far I have tried:

  • SG Protractor Tools (https://github.com/SunGard-Labs/sg-protractor-tools) which allow to repeat the same scenario several times and find the memory growth. I have discarded it since it does not allow checking memory usage for a single scenario (https://github.com/SunGard-Labs/sg-protractor-tools/issues/3).
  • Extracting the memory values from the browser object, which does not seem to work (or I could not get to work) to integrate with the specs -> Assign a value returned from a promise to a global variable

Any other ideas?

like image 238
Tedi Avatar asked Oct 30 '22 20:10

Tedi


1 Answers

This can be done by invoking browser.executeScript()

Use window.performance.memory for Chrome to fetch the performance parameters The below code worked all good for me.

https://docs.webplatform.org/wiki/apis/timing/properties/memory

it('Dummy Test', function(){
    //Fetch the browser memory parameters before execution
    browser.executeScript('return window.performance.memory').then(function(memoryInfo){
        console.log(memoryInfo)
        var beforejsHeapSizeLimit = memoryInfo.jsHeapSizeLimit;
        var beforeusedJSHeapSize = memoryInfo.usedJSHeapSize;
        var beforetotalJSHeapSize = memoryInfo.totalJSHeapSize;

        // Have all your code to open browser .. navigate pages etc
        browser.driver.get("https://wordpress.com/");
        browser.driver.get("http://www.adobe.com/software/flash/about/");
        // Once you are done compare before and after values

        //Fetch the browser memory parameters after execution and compare
        browser.executeScript('return window.performance.memory').then(function(aftermemoryInfo) {
            console.log(aftermemoryInfo)
            var afterjsHeapSizeLimit = aftermemoryInfo.jsHeapSizeLimit;
            var afterusedJSHeapSize = aftermemoryInfo.usedJSHeapSize;
            var aftertotalJSHeapSize = aftermemoryInfo.totalJSHeapSize;
            expect((parseInt(afterusedJSHeapSize)-parseInt(beforeusedJSHeapSize))<10000000).toBe.true;
        });
    });

});
like image 108
AdityaReddy Avatar answered Dec 10 '22 06:12

AdityaReddy