This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
first is not friendly with isPresent #2917
Open
Description
ElementArrayFinder.first()
(and probably last too) is not currently friendly with the ElementFinder.isPresent. I.e. assume the following test:
it('First should be friendly with isPresent', function () {
expect(element.all(by.css('nonexistingselector')).first().isPresent()).toBe(false);
});
That is quite natural assumption but the test is not passing. It fails currently with the error:
Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By.cssSelector("nonexistingselector")
Can this be improoved somehow?
PS.
Actually I faced it in a more complex case where I was trying to do something like this:
function byExactText(text) {
// Cannot use by.cssContainingText here because
// I need item with name "Element1" whereas
// there also is another item with name "Element1 Extended".
return element.all(by.css('.item')).filter(function(item) {
return item.element(by.css('.name')).getText().then(function(text) {
return text === name;
});
}).first();
}
expect(byExactText('Element1').isPresent()).toBe('false');
expect(byExactText('AbsentElmnt').isPresent()).toBe('false');
And here I cannot easily replace to something like:
byExactText('AbsentElmnt').then(function(items){
return items.length > 0 ? items[0] : undefined; // well, what to replace the indefined with?
}).isPresent();
Because the yet-unresolved-promise returned from "then" is not an instance of ElementFinder and has no appropriate methods...
PPS. This issue has something common with #2314