diff --git a/lib/element.ts b/lib/element.ts index 5dc5c7c06..b60b004da 100644 --- a/lib/element.ts +++ b/lib/element.ts @@ -428,6 +428,22 @@ export class ElementArrayFinder extends WebdriverWebElement { }); } + /** + * Returns true if there are any elements present that match the finder. + * + * @alias element.all(locator).isPresent() + * + * @example + * expect($('.item').isPresent()).toBeTruthy(); + * + * @returns {Promise} + */ + isPresent(): wdpromise.Promise { + return this.count().then((count) => { + return count > 0; + }); + } + /** * Returns the most relevant locator. * diff --git a/spec/basic/elements_spec.js b/spec/basic/elements_spec.js index c36eb2a0b..ed2a3121f 100644 --- a/spec/basic/elements_spec.js +++ b/spec/basic/elements_spec.js @@ -357,6 +357,13 @@ describe('ElementArrayFinder', function() { expect(element.all(by.binding('doesnotexist')).count()).toEqual(0); }); + it('supports isPresent()', function() { + browser.get('index.html#/form'); + + expect(element.all(by.model('color')).isPresent()).toBeTruthy(); + expect(element.all(by.binding('doesnotexist')).isPresent()).toBeFalsy(); + }); + it('should return not present when an element disappears within an array', function() { browser.get('index.html#/form');