While testing an AngularJS app with Protractor, I have come across a perplexing issue:
var counter = 0;
redButton.click();
allImages.each(function(element) {
element.isDisplayed().then(function(isDispl){
if(isDispl === true){
expect(element.getInnerHtml()).toContain('red');
counter++;
console.log("I'm here!")
}
});
});
console.log(counter);
The displayed output shows:
0
I'm here!
I'm here!
But what I expected was:
I'm here!
I'm here!
2
Why is this happening? Why does the variable 'counter' not equal 2 when the condition isDispl === true twice?