我有这个JS:
var getAccountNumberArray = element.all(by.repeater('currentUserAccount in currentUserAccounts').column('currentUserAccount.accountNumber')).map(function (accounts) {
return accounts.getText();
});
getAccountNumberArray.then(function (textArr) {
console.log(textArr);
});
});
效果很好,但是我希望将它放在一个函数中,以便在我喜欢的时候调用,
MyAccountsPage.prototype.getAccountNumberArray = function () {
element.all(by.repeater('currentUserAccount in currentUserAccounts').column('currentUserAccount.accountNumber')).map(function (accounts){
return accounts.getText();
});
};
为什么此函数会返回undefined
?
答案 0 :(得分:1)
从函数返回结果
MyAccountsPage.prototype.getAccountNumberArray = function() {
return element.all(by.repeater('currentUserAccount in currentUserAccounts').column('currentUserAccount.accountNumber')).map(function(accounts) {
return accounts.getText();
});
};
答案 1 :(得分:0)
MyAccountsPage.prototype.getAccountNumberArray = function () {
return element.all(by.repeater('currentUserAccount in currentUserAccounts').column('currentUserAccount.accountNumber')).map(function (accounts){
return accounts.getText();
});
};
您需要返回它 - 没有显式return
语句的函数返回undefined
。