Need some help with control flow
I added a console.log and i know it properly goes through repeater at least up to the getText. It all works when the item I want is the first on the list, but if it is not the first, it just exits and does not do anything.
var fileName = this.fileName;
browser.findElements ( by.repeater ( 'file in files' ) ).then ( function ( documentsList ) {
documentsList.some ( function ( file ) {
return file.$('.file-list-item-name.ng-binding').getText ().then ( function ( text ) {
if ( text.trim () == uploadFileName ) {
expect ( file.$('.file-list-item-icon.ng-isolate-scope.ng-binding').getAttribute ( 'data-file-type' ) ).toContain ( uploadFileExtension.substring ( 0,3 ) );
expect ( file.$('.file-list-item-name.ng-binding').getText () ).toContain ( uploadFileName );
file.$('.file-list-item-name.ng-binding' ).click();
helper.wait ( fileName, "Doc Name" );
helper.wait ( $ ( 'iframe' ), "Attachment Iframe" );
browser.switchTo ().frame ( 0 );
helper.wait ( $ ( '.bg-img' ), "Attachment" );
browser.switchTo ().defaultContent ();
break;
}
browser.navigate ().back ();
helper.waitForRepeaterToPopulate ( 'file in files', "File Items" );
return true;
}
} )
} )
} );
The issue is that documentsList is a plain old array that doesn't understand promises. So, when you do documentsList.some and pass in a function which returns a promise, the plain old array interprets any promise as true and so it only ever processes the first thing.
There was a PR to add a promise-aware some function (so you could do findElements(...).some(...), but the author seems to have dropped it. See https://github.com/angular/protractor/pull/627
Ahhh.... that definitely is the reason. But on the other hand, 0.22 just added By.cssContainingText which works wonderfully for what I want to do!
Thanks!