@@ -29,11 +29,12 @@ util.inherits(ProtractorBy, WebdriverBy);
29
29
*
30
30
* @example
31
31
* // Add the custom locator.
32
- * by.addLocator('buttonTextSimple', function(buttonText, opt_parentElement) {
32
+ * by.addLocator('buttonTextSimple',
33
+ * function(buttonText, opt_parentElement, opt_rootSelector) {
33
34
* // This function will be serialized as a string and will execute in the
34
35
* // browser. The first argument is the text for the button. The second
35
36
* // argument is the parent element, if any.
36
- * var using = opt_parentElement || document,
37
+ * var using = opt_parentElement || document.querySelector(opt_rootSelector) ,
37
38
* buttons = using.querySelectorAll('button');
38
39
*
39
40
* // Return an array of buttons with the text.
@@ -50,18 +51,20 @@ util.inherits(ProtractorBy, WebdriverBy);
50
51
* @param {Function|string } script A script to be run in the context of
51
52
* the browser. This script will be passed an array of arguments
52
53
* that contains any args passed into the locator followed by the
53
- * element scoping the search. It should return an array of elements.
54
+ * element scoping the search and the css selector for the root angular
55
+ * element. It should return an array of elements.
54
56
*/
55
57
ProtractorBy . prototype . addLocator = function ( name , script ) {
56
58
this [ name ] = function ( ) {
57
59
var locatorArguments = arguments ;
58
60
return {
59
- findElementsOverride : function ( driver , using ) {
61
+ findElementsOverride : function ( driver , using , rootSelector ) {
60
62
var findElementArguments = [ script ] ;
61
63
for ( var i = 0 ; i < locatorArguments . length ; i ++ ) {
62
64
findElementArguments . push ( locatorArguments [ i ] ) ;
63
65
}
64
66
findElementArguments . push ( using ) ;
67
+ findElementArguments . push ( rootSelector ) ;
65
68
66
69
return driver . findElements (
67
70
webdriver . By . js . apply ( webdriver . By , findElementArguments ) ) ;
@@ -93,10 +96,10 @@ ProtractorBy.prototype.addLocator = function(name, script) {
93
96
*/
94
97
ProtractorBy . prototype . binding = function ( bindingDescriptor ) {
95
98
return {
96
- findElementsOverride : function ( driver , using ) {
99
+ findElementsOverride : function ( driver , using , rootSelector ) {
97
100
return driver . findElements (
98
101
webdriver . By . js ( clientSideScripts . findBindings ,
99
- bindingDescriptor , false , using ) ) ;
102
+ bindingDescriptor , false , using , rootSelector ) ) ;
100
103
} ,
101
104
toString : function toString ( ) {
102
105
return 'by.binding("' + bindingDescriptor + '")' ;
@@ -125,10 +128,10 @@ ProtractorBy.prototype.binding = function(bindingDescriptor) {
125
128
*/
126
129
ProtractorBy . prototype . exactBinding = function ( bindingDescriptor ) {
127
130
return {
128
- findElementsOverride : function ( driver , using ) {
131
+ findElementsOverride : function ( driver , using , rootSelector ) {
129
132
return driver . findElements (
130
133
webdriver . By . js ( clientSideScripts . findBindings ,
131
- bindingDescriptor , true , using ) ) ;
134
+ bindingDescriptor , true , using , rootSelector ) ) ;
132
135
} ,
133
136
toString : function toString ( ) {
134
137
return 'by.exactBinding("' + bindingDescriptor + '")' ;
@@ -152,9 +155,10 @@ ProtractorBy.prototype.exactBinding = function(bindingDescriptor) {
152
155
*/
153
156
ProtractorBy . prototype . model = function ( model ) {
154
157
return {
155
- findElementsOverride : function ( driver , using ) {
158
+ findElementsOverride : function ( driver , using , rootSelector ) {
156
159
return driver . findElements (
157
- webdriver . By . js ( clientSideScripts . findByModel , model , using ) ) ;
160
+ webdriver . By . js (
161
+ clientSideScripts . findByModel , model , using , rootSelector ) ) ;
158
162
} ,
159
163
toString : function toString ( ) {
160
164
return 'by.model("' + model + '")' ;
@@ -176,10 +180,10 @@ ProtractorBy.prototype.model = function(model) {
176
180
*/
177
181
ProtractorBy . prototype . buttonText = function ( searchText ) {
178
182
return {
179
- findElementsOverride : function ( driver , using ) {
183
+ findElementsOverride : function ( driver , using , rootSelector ) {
180
184
return driver . findElements (
181
185
webdriver . By . js ( clientSideScripts . findByButtonText ,
182
- searchText , using ) ) ;
186
+ searchText , using , rootSelector ) ) ;
183
187
} ,
184
188
toString : function toString ( ) {
185
189
return 'by.buttonText("' + searchText + '")' ;
@@ -201,10 +205,10 @@ ProtractorBy.prototype.buttonText = function(searchText) {
201
205
*/
202
206
ProtractorBy . prototype . partialButtonText = function ( searchText ) {
203
207
return {
204
- findElementsOverride : function ( driver , using ) {
208
+ findElementsOverride : function ( driver , using , rootSelector ) {
205
209
return driver . findElements (
206
210
webdriver . By . js ( clientSideScripts . findByPartialButtonText ,
207
- searchText , using ) ) ;
211
+ searchText , using , rootSelector ) ) ;
208
212
} ,
209
213
toString : function toString ( ) {
210
214
return 'by.partialButtonText("' + searchText + '")' ;
@@ -266,30 +270,30 @@ ProtractorBy.prototype.partialButtonText = function(searchText) {
266
270
*/
267
271
ProtractorBy . prototype . repeater = function ( repeatDescriptor ) {
268
272
return {
269
- findElementsOverride : function ( driver , using ) {
273
+ findElementsOverride : function ( driver , using , rootSelector ) {
270
274
return driver . findElements (
271
275
webdriver . By . js ( clientSideScripts . findAllRepeaterRows ,
272
- repeatDescriptor , using ) ) ;
276
+ repeatDescriptor , using , rootSelector ) ) ;
273
277
} ,
274
278
toString : function toString ( ) {
275
279
return 'by.repeater("' + repeatDescriptor + '")' ;
276
280
} ,
277
281
row : function ( index ) {
278
282
return {
279
- findElementsOverride : function ( driver , using ) {
283
+ findElementsOverride : function ( driver , using , rootSelector ) {
280
284
return driver . findElements (
281
285
webdriver . By . js ( clientSideScripts . findRepeaterRows ,
282
- repeatDescriptor , index , using ) ) ;
286
+ repeatDescriptor , index , using , rootSelector ) ) ;
283
287
} ,
284
288
toString : function toString ( ) {
285
289
return 'by.repeater(' + repeatDescriptor + '").row("' + index + '")"' ;
286
290
} ,
287
291
column : function ( binding ) {
288
292
return {
289
- findElementsOverride : function ( driver , using ) {
293
+ findElementsOverride : function ( driver , using , rootSelector ) {
290
294
return driver . findElements (
291
295
webdriver . By . js ( clientSideScripts . findRepeaterElement ,
292
- repeatDescriptor , index , binding , using ) ) ;
296
+ repeatDescriptor , index , binding , using , rootSelector ) ) ;
293
297
} ,
294
298
toString : function toString ( ) {
295
299
return 'by.repeater("' + repeatDescriptor + '").row("' + index +
@@ -301,21 +305,21 @@ ProtractorBy.prototype.repeater = function(repeatDescriptor) {
301
305
} ,
302
306
column : function ( binding ) {
303
307
return {
304
- findElementsOverride : function ( driver , using ) {
308
+ findElementsOverride : function ( driver , using , rootSelector ) {
305
309
return driver . findElements (
306
310
webdriver . By . js ( clientSideScripts . findRepeaterColumn ,
307
- repeatDescriptor , binding , using ) ) ;
311
+ repeatDescriptor , binding , using , rootSelector ) ) ;
308
312
} ,
309
313
toString : function toString ( ) {
310
314
return 'by.repeater("' + repeatDescriptor + '").column("' +
311
315
binding + '")' ;
312
316
} ,
313
317
row : function ( index ) {
314
318
return {
315
- findElementsOverride : function ( driver , using ) {
319
+ findElementsOverride : function ( driver , using , rootSelector ) {
316
320
return driver . findElements (
317
321
webdriver . By . js ( clientSideScripts . findRepeaterElement ,
318
- repeatDescriptor , index , binding , using ) ) ;
322
+ repeatDescriptor , index , binding , using , rootSelector ) ) ;
319
323
} ,
320
324
toString : function toString ( ) {
321
325
return 'by.repeater("' + repeatDescriptor + '").column("' +
@@ -343,10 +347,10 @@ ProtractorBy.prototype.repeater = function(repeatDescriptor) {
343
347
*/
344
348
ProtractorBy . prototype . cssContainingText = function ( cssSelector , searchText ) {
345
349
return {
346
- findElementsOverride : function ( driver , using ) {
350
+ findElementsOverride : function ( driver , using , rootSelector ) {
347
351
return driver . findElements (
348
352
webdriver . By . js ( clientSideScripts . findByCssContainingText ,
349
- cssSelector , searchText , using ) ) ;
353
+ cssSelector , searchText , using , rootSelector ) ) ;
350
354
} ,
351
355
toString : function toString ( ) {
352
356
return 'by.cssContainingText("' + cssSelector + '", "' + searchText + '")' ;
@@ -374,9 +378,10 @@ ProtractorBy.prototype.cssContainingText = function(cssSelector, searchText) {
374
378
*/
375
379
ProtractorBy . prototype . options = function ( optionsDescriptor ) {
376
380
return {
377
- findElementsOverride : function ( driver , using ) {
381
+ findElementsOverride : function ( driver , using , rootSelector ) {
378
382
return driver . findElements (
379
- webdriver . By . js ( clientSideScripts . findByOptions , optionsDescriptor , using ) ) ;
383
+ webdriver . By . js ( clientSideScripts . findByOptions , optionsDescriptor ,
384
+ using , rootSelector ) ) ;
380
385
} ,
381
386
toString : function toString ( ) {
382
387
return 'by.option("' + optionsDescriptor + '")' ;
0 commit comments