我正在尝试从量角器读取浏览器内存值并将它们存储在全局对象中。为此,我获取 window.performance.memory 对象,然后解决检查每个内存值的承诺。
问题是我似乎无法将值分配给全局变量。我尝试过以下代码,但似乎效果不太好:
this.measureMemory = function () {
var HeapSizeLimit;
browser.driver.executeScript(function () {
return window.performance.memory;
}).then(function (memoryValues) {
HeapSizeLimit = memoryValues.jsHeapSizeLimit;
console.log('Variable within the promise: ' + HeapSizeLimit);
});
console.log('Variable outside the promise: ' + HeapSizeLimit);
};
这将返回:
Variable outside the promise: undefined
Variable within the promise: 750780416
Because
console.log('Variable outside the promise: ' + HeapSizeLimit);
之前执行过HeapSizeLimit = memoryValues.jsHeapSizeLimit;
。如果它在 Promise 之后,并不意味着执行顺序是相同的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)