I am calling deferred.fulfill() with a Protractor elementfinder as a parameter. When placing a breakpoint on the fulfill I can see that the elementfinder "solutionElement" is not null. The promise is resolved and my "then" callback is executed. However the value of "myElement" in the callback is null.
If I don't pass the elementfinder to the fulfill and instead use some other value(i.e. the "cnt" var) the "myElement" variable resolves to the actual value of "cnt".
I'm wondering if the issue is related to the fact that my fulfill call is within a then callback, but I don't understand for sure.
Any help/advice would be appreciated. Thank You
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;
};