@@ -19,6 +19,11 @@ for (foo in webdriver) {
19
19
exports [ foo ] = webdriver [ foo ] ;
20
20
}
21
21
22
+ /**
23
+ * @type {ProtractorBy }
24
+ */
25
+ exports . By = new ProtractorBy ( ) ;
26
+
22
27
/**
23
28
* Mix a function from one object onto another. The function will still be
24
29
* called in the context of the original object.
@@ -140,35 +145,6 @@ var buildMultiCssHelper = function(ptor) {
140
145
} ;
141
146
} ;
142
147
143
- /**
144
- * Builds a single web element from a locator with a findElementsOverride.
145
- * Throws an error if an element is not found, and issues a warning
146
- * if more than one element is described by the selector.
147
- *
148
- * @param {Protractor } ptor The protractor instance.
149
- * @param {webdriver.WebElement } using A WebElement to scope the find,
150
- * or null.
151
- * @param {webdriver.Locator } locator
152
- * @return {webdriver.WebElement }
153
- */
154
- var findElementsOverrideHelper = function ( ptor , using , locator ) {
155
- // We need to return a WebElement, so we construct one using a promise
156
- // which will resolve to a WebElement.
157
- return new webdriver . WebElement (
158
- ptor . driver ,
159
- locator . findElementsOverride ( ptor . driver , using ) . then ( function ( arr ) {
160
- if ( ! arr . length ) {
161
- throw new Error ( 'No element found using locator: ' + locator . message ) ;
162
- }
163
- if ( arr . length > 1 ) {
164
- util . puts ( 'warning: more than one element found for locator ' +
165
- locator . message +
166
- '- you may need to be more specific' ) ;
167
- }
168
- return arr [ 0 ] ;
169
- } ) ) ;
170
- } ;
171
-
172
148
/**
173
149
* @param {webdriver.WebDriver } webdriver
174
150
* @param {string= } opt_baseUrl A base URL to run get requests against.
@@ -335,7 +311,7 @@ Protractor.prototype.wrapWebElement = function(element) {
335
311
336
312
var found ;
337
313
if ( locator . findElementsOverride ) {
338
- found = findElementsOverrideHelper ( thisPtor , element , locator ) ;
314
+ found = thisPtor . findElementsOverrideHelper_ ( element , locator ) ;
339
315
} else {
340
316
found = originalFindElement . apply ( element , arguments ) ;
341
317
}
@@ -425,7 +401,7 @@ Protractor.prototype.findElement = function(locator, varArgs) {
425
401
this . waitForAngular ( ) ;
426
402
427
403
if ( locator . findElementsOverride ) {
428
- found = findElementsOverrideHelper ( this , null , locator ) ;
404
+ found = this . findElementsOverrideHelper_ ( null , locator ) ;
429
405
} else {
430
406
found = this . driver . findElement ( locator , varArgs ) ;
431
407
}
@@ -597,6 +573,35 @@ Protractor.prototype.debugger = function() {
597
573
} ) ;
598
574
} ;
599
575
576
+ /**
577
+ * Builds a single web element from a locator with a findElementsOverride.
578
+ * Throws an error if an element is not found, and issues a warning
579
+ * if more than one element is described by the selector.
580
+ *
581
+ * @private
582
+ * @param {webdriver.WebElement } using A WebElement to scope the find,
583
+ * or null.
584
+ * @param {webdriver.Locator } locator
585
+ * @return {webdriver.WebElement }
586
+ */
587
+ Protractor . prototype . findElementsOverrideHelper_ = function ( using , locator ) {
588
+ // We need to return a WebElement, so we construct one using a promise
589
+ // which will resolve to a WebElement.
590
+ return new webdriver . WebElement (
591
+ this . driver ,
592
+ locator . findElementsOverride ( this . driver , using ) . then ( function ( arr ) {
593
+ if ( ! arr . length ) {
594
+ throw new Error ( 'No element found using locator: ' + locator . message ) ;
595
+ }
596
+ if ( arr . length > 1 ) {
597
+ util . puts ( 'warning: more than one element found for locator ' +
598
+ locator . message +
599
+ '- you may need to be more specific' ) ;
600
+ }
601
+ return arr [ 0 ] ;
602
+ } ) ) ;
603
+ } ;
604
+
600
605
/**
601
606
* Create a new instance of Protractor by wrapping a webdriver instance.
602
607
*
@@ -628,9 +633,3 @@ exports.setInstance = function(ptor) {
628
633
exports . getInstance = function ( ) {
629
634
return instance ;
630
635
}
631
-
632
-
633
- /**
634
- * @type {ProtractorBy }
635
- */
636
- exports . By = new ProtractorBy ( ) ;
0 commit comments