跟踪 Protractor 测试执行所消耗的浏览器内存的最有效方法是什么?
What is the most efficient way to track browser memory consumed by the execution of a Protractor test?
想法是:
- 在开始测试之前测量 usedJSHeapSize。
- 完成测试后测量usedJSHeapSize。
- 比较 1 和 2 的值,如果大小增加超过定义的阈值,则场景失败。
到目前为止我已经尝试过:
- SG 量角器工具(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)。
- 从浏览器对象中提取内存值,这似乎无法(或者我无法开始工作)与规范集成 -> Assign a value returned from a promise to a global variable
还有其他想法吗?
这可以通过调用 browser.executeScript()
来完成
对Chrome使用window.performance.memory获取性能参数
下面的代码对我很有用。
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;
});
});
});
想法是:
- 在开始测试之前测量 usedJSHeapSize。
- 完成测试后测量usedJSHeapSize。
- 比较 1 和 2 的值,如果大小增加超过定义的阈值,则场景失败。
到目前为止我已经尝试过:
- SG 量角器工具(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)。
- 从浏览器对象中提取内存值,这似乎无法(或者我无法开始工作)与规范集成 -> Assign a value returned from a promise to a global variable
还有其他想法吗?
这可以通过调用 browser.executeScript()
来完成对Chrome使用window.performance.memory获取性能参数 下面的代码对我很有用。
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;
});
});
});