跟踪执行Protractor测试所消耗的浏览器内存的最有效方法是什么?

时间:2016-09-15 11:01:40

标签: memory-leaks protractor performance-testing

这个想法是:

  1. 在开始测试之前测量usedJSHeapSize。
  2. 完成测试后测量usedJSHeapSize。
  3. 比较1和2的值,如果大小超过定义的阈值,则表示方案失败。
  4. 到目前为止,我已经尝试过:

    还有其他想法吗?

1 个答案:

答案 0 :(得分:2)

这可以通过调用browser.executeScript()

来完成

使用window.performance.memory Chrome来获取效果参数 以下代码对我有用。

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;
        });
    });

});