0
这更像是一个JavaScript问题,但它正在尝试使用量角器测试来实现。量角器函数返回undefined?
//fileA.js
element(by.id('page-element').getText().then(function() {
var currentPremium = fileB.getSixMonthPremium(); // calls the function in fileB.js
element(by.id('page-element').getText().then(function() {
console.log(currentPremium); // prints undefined
fileB.compareValue(currentPremium, ..., ...,);
});
});
//fileB.js
this.getSixMonthPremium() = function() {
element(by.id('full-premium').isDisplayed().then(function(displayed) {
if (displayed) {
element(by.id('full-premium').getText().then(function(currentPremium) {
console.log('Current Premium - ' + currentPremium); // prints string of $XXX.xx
return currentPremium; //seems to be returning undefined?
});
}
});
});
当试图使用变量currentPremium
它从函数调用返回后,它总是不确定的。我究竟做错了什么?
谢谢!我知道这是异步/承诺相关的东西,但我无法通过搜索Google找到我需要的东西。我需要让自己成为一本JavaScript书籍或找到一些好的在线内容:) – DrZoo