Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(protractor): isPresent() should work with out of bounds errors (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelin committed Apr 11, 2016
1 parent 6f3a02f commit bd78dfc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ ElementArrayFinder.prototype.get = function(index) {
i = parentWebElements.length + i;
}
if (i < 0 || i >= parentWebElements.length) {
throw new Error('Index out of bound. Trying to access element at ' +
'index: ' + index + ', but there are only ' +
parentWebElements.length + ' elements that match locator ' +
self.locator_.toString());
throw new webdriver.error.NoSuchElementError('Index out of bound. ' +
'Trying to access element at index: ' + index + ', but there are ' +
'only ' + parentWebElements.length + ' elements that match ' +
'locator ' + self.locator_.toString());
}
return [parentWebElements[i]];
});
Expand Down
7 changes: 7 additions & 0 deletions spec/basic/elements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ describe('ElementFinder', function() {
});
});

it('isPresent() should be friendly with out of bounds error', function () {
browser.get('index.html#/form');
var elementsNotPresent = element.all(by.id('notPresentElementID'));
expect(elementsNotPresent.first().isPresent()).toBe(false);
expect(elementsNotPresent.last().isPresent()).toBe(false);
});

it('isPresent() should not raise error on chained finders', function() {
browser.get('index.html#/form');
var elmFinder = $('.nopenopenope').element(by.binding('greet'));
Expand Down

0 comments on commit bd78dfc

Please sign in to comment.