저는 각도기에서 브라우저 메모리 값을 읽고 전역 객체에 저장하려고합니다. 이를 위해 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);
};
이 반환 console.log('Variable outside the promise: ' + HeapSizeLimit);
이 HeapSizeLimit = memoryValues.jsHeapSizeLimit;
전에 실행
Variable outside the promise: undefined
Variable within the promise: 750780416
당신은 확실히'then' 함수에서 약속 밖의 값에 할당 할 수 있지만'then' 함수가 실제로 실행 된 후에 시간순으로 설정할 수는 없습니다. – apsillers
감사합니다. @apsillers. 이 설명은 문제가 무엇인지 이해하는 데 매우 유용했습니다. – Tedi