【发布时间】:2014-06-14 11:21:38
【问题描述】:
我使用 Protractor elementfinder 作为参数调用 deferred.fulfill()。在完成上放置断点时,我可以看到元素查找器“solutionElement”不为空。承诺得到解决,我的“then”回调被执行。但是回调中“myElement”的值为null。
如果我不将元素查找器传递给完成,而是使用其他值(即“cnt”var),“myElement”变量将解析为“cnt”的实际值。
我想知道这个问题是否与我的完成调用在 then 回调中这一事实有关,但我不确定。
任何帮助/建议将不胜感激。谢谢你
it('Should select when clicked',function() {
sb.getSolutionElementIndexByName("test").then(function(myElement) {
myElement.click();
});
});
SbPageObject.prototype.getSolutionElementIndexByName = function(name){
var deferred = protractor.promise.defer();
var cnt = 0;
var notFulFilled = true;
var allSolutions = this.allSolutions;
allSolutions.count().then(function(solCnt){
allSolutions.each(function (solutionElement) {
solutionElement.element(by.className("sb-solution-name")).getText().
then(function (solutionText) {
if (solutionText === name) {
console.log("*****Fullfiled");
deferred.fulfill(solutionElement);
notFulFilled = false;
}
//if this is the last element and it's still not a match, reject promise
else if (cnt + 1 == solCnt){
deferred.reject(new Error ("Solution " + name + " was not found."));
}
cnt++;
});
});
});
return deferred.promise;
};
【问题讨论】:
标签: promise protractor