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

Commit 9e426df

Browse files
committed
fix(locators): using $().$$() should return an ElementArrayFinder
Prior, $(foo).$$(bar) would return a promise which resolved to an array of WebElements. This is unexpected, since $(foo).$(bar) returns an ElementFinder, and element(by.css(foo)).element.all(by.css(bar)) returns an ElementArrayFinder. Fixed so things are more consistent. Closes #640
1 parent 8b088fd commit 9e426df

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/protractor.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ var buildElementHelper = function(ptor, opt_usingChain) {
106106
var elementFinder = {};
107107

108108
var webElementFns = WEB_ELEMENT_FUNCTIONS.concat(
109-
['findElements', 'isElementPresent', 'evaluate', '$$']);
109+
['findElements', 'isElementPresent', 'evaluate']);
110110
webElementFns.forEach(function(fnName) {
111111
elementFinder[fnName] = function() {
112112
var callerError = new Error();
@@ -220,6 +220,11 @@ var buildElementHelper = function(ptor, opt_usingChain) {
220220
webdriver.By.css(cssSelector));
221221
};
222222

223+
elementFinder.$$ = function(cssSelector) {
224+
return buildElementHelper(ptor, usingChain).all(
225+
webdriver.By.css(cssSelector));
226+
};
227+
223228
return elementFinder;
224229
};
225230

spec/basic/findelements_spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ describe('chaining find elements', function() {
416416
});
417417
});
418418

419+
it('should chain element.all after element', function() {
420+
expect(element(by.id('baz')).element.all(by.binding('item')).count()).
421+
toEqual(2);
422+
});
423+
419424
it('should wait to grab multiple chained elements',
420425
function() {
421426
browser.driver.get('about:blank');
@@ -644,6 +649,16 @@ describe('shortcut css notation', function() {
644649
});
645650
});
646651
});
652+
653+
it('should chain $$ with $', function() {
654+
var withoutShortcutCount =
655+
element(by.css('select')).element.all(by.css('option')).then(function(options) {
656+
return options.length;
657+
});
658+
var withShortcutCount = $('select').$$('option').count();
659+
660+
expect(withoutShortcutCount).toEqual(withShortcutCount);
661+
});
647662
});
648663

649664
describe('wrapping web driver elements', function() {

0 commit comments

Comments
 (0)