From 7bf8ac47b3296fc5969c6e56f70ead30fba5b7a7 Mon Sep 17 00:00:00 2001 From: mgiambalvo Date: Wed, 18 Jan 2017 13:41:36 -0800 Subject: [PATCH] feat(elements): Add isPresent() to ElementArrayFinder. (#3974) --- lib/element.ts | 16 ++++++++++++++++ spec/basic/elements_spec.js | 7 +++++++ 2 files changed, 23 insertions(+) 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');