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

Commit dd06756

Browse files
marcenucjuliemr
authored andcommitted
fix(clientsidescripts): findElements and isElementPresent for protractor.By.select
1 parent 487a2b5 commit dd06756

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

lib/clientsidescripts.js

+42
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,27 @@ clientSideScripts.findSelect = function() {
256256
}
257257
};
258258

259+
/**
260+
* Find multiple select elements by model name.
261+
*
262+
* arguments[0] {Element} The scope of the search.
263+
* arguments[1] {string} The model name.
264+
*
265+
* @return {Array.<Element>} The matching select elements.
266+
*/
267+
clientSideScripts.findSelects = function() {
268+
var using = arguments[0] || document;
269+
var model = arguments[1];
270+
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
271+
for (var p = 0; p < prefixes.length; ++p) {
272+
var selector = 'select[' + prefixes[p] + 'model="' + model + '"]';
273+
var inputs = using.querySelectorAll(selector);
274+
if (inputs.length) {
275+
return inputs;
276+
}
277+
}
278+
};
279+
259280
/**
260281
* Find an selected option element by model name.
261282
*
@@ -278,6 +299,27 @@ clientSideScripts.findSelectedOption = function() {
278299
}
279300
};
280301

302+
/**
303+
* Find selected option elements by model name.
304+
*
305+
* arguments[0] {Element} The scope of the search.
306+
* arguments[1] {string} The model name.
307+
*
308+
* @return {Array.<Element?} The matching select elements.
309+
*/
310+
clientSideScripts.findSelectedOptions = function() {
311+
var using = arguments[0] || document;
312+
var model = arguments[1];
313+
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
314+
for (var p = 0; p < prefixes.length; ++p) {
315+
var selector = 'select[' + prefixes[p] + 'model="' + model + '"] option:checked';
316+
var inputs = using.querySelectorAll(selector);
317+
if (inputs.length) {
318+
return inputs;
319+
}
320+
}
321+
};
322+
281323
/**
282324
* Find a textarea element by model name.
283325
*

lib/locators.js

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ ProtractorBy.prototype.select = function(model) {
5151
findOverride: function(driver, using) {
5252
return driver.findElement(
5353
webdriver.By.js(clientSideScripts.findSelect), using, model);
54+
},
55+
findArrayOverride: function(driver, using) {
56+
return driver.findElements(
57+
webdriver.By.js(clientSideScripts.findSelects), using, model);
5458
}
5559
};
5660
};
@@ -60,6 +64,10 @@ ProtractorBy.prototype.selectedOption = function(model) {
6064
findOverride: function(driver, using) {
6165
return driver.findElement(
6266
webdriver.By.js(clientSideScripts.findSelectedOption), using, model);
67+
},
68+
findArrayOverride: function(driver, using) {
69+
return driver.findElements(
70+
webdriver.By.js(clientSideScripts.findSelectedOptions), using, model);
6371
}
6472
};
6573
};

spec/findelements_spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ describe('finding elements', function() {
8282
});
8383
});
8484

85+
it('should find multiple selects', function() {
86+
ptor.findElements(protractor.By.select('dc.color')).then(function(arr) {
87+
expect(arr.length).toEqual(3);
88+
});
89+
});
90+
91+
it('should find multiple selected options', function() {
92+
ptor.findElements(protractor.By.selectedOption('dc.color')).then(function(arr) {
93+
expect(arr.length).toEqual(3);
94+
expect(arr[0].getText()).toBe('red');
95+
expect(arr[1].getText()).toBe('green');
96+
expect(arr[2].getText()).toBe('blue');
97+
});
98+
});
99+
85100
it('should find a repeater by partial match', function() {
86101
var fullMatch = ptor.findElement(
87102
protractor.By.repeater('baz in days | filter:\'T\'').

testapp/app/js/controllers.js

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ function FormCtrl($scope) {
105105
$scope.color = "blue";
106106
$scope.show = true;
107107
$scope.days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
108+
$scope.colors = ['red', 'green', 'blue'];
109+
$scope.dayColors = [{day: 'Mon', color: 'red'}, {day: 'Tue', color: 'green'}, {day: 'Wed', color: 'blue'}];
108110
}
109111
FormCtrl.$inject = ['$scope'];
110112

testapp/app/partials/form.html

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<input ng-model="color" value="green" type="radio"/> green <br/>
1111
<input ng-model="color" value="red" type="radio"/> red <br/>
1212
</div>
13+
<ul><li ng-repeat="dc in dayColors"><select ng-model="dc.color" ng-options="c for c in colors"></select></li></ul>
1314
<div>
1415
<input ng-model="show" type="checkbox"/> Show?
1516
<span id="shower" ng-show="show">Shown!!</span>

0 commit comments

Comments
 (0)