|
1 |
| -var util = require('util'); |
2 | 1 | var webdriver = require('selenium-webdriver');
|
3 | 2 | var log = require('./logger.js');
|
4 | 3 | var clientSideScripts = require('./clientsidescripts.js');
|
5 | 4 |
|
6 | 5 | var WEB_ELEMENT_FUNCTIONS = [
|
7 | 6 | 'click', 'sendKeys', 'getTagName', 'getCssValue', 'getAttribute', 'getText',
|
8 | 7 | 'getSize', 'getLocation', 'isEnabled', 'isSelected', 'submit', 'clear',
|
9 |
| - 'isDisplayed', 'getOuterHtml', 'getInnerHtml', 'getId']; |
| 8 | + 'isDisplayed', 'getOuterHtml', 'getInnerHtml', 'getId', 'getRawId']; |
10 | 9 |
|
11 | 10 | /**
|
12 | 11 | * ElementArrayFinder is used for operations on an array of elements (as opposed
|
@@ -78,7 +77,6 @@ var ElementArrayFinder = function(ptor, getWebElements, locator, opt_actionResul
|
78 | 77 | };
|
79 | 78 | });
|
80 | 79 | };
|
81 |
| -util.inherits(ElementArrayFinder, webdriver.promise.Promise); |
82 | 80 |
|
83 | 81 | exports.ElementArrayFinder = ElementArrayFinder;
|
84 | 82 |
|
@@ -209,18 +207,17 @@ ElementArrayFinder.prototype.filter = function(filterFn) {
|
209 | 207 | var elementFinder =
|
210 | 208 | ElementFinder.fromWebElement_(self.ptor_, parentWebElement, self.locator_);
|
211 | 209 |
|
212 |
| - var filterResults = filterFn(elementFinder, index); |
213 |
| - if (filterResults instanceof webdriver.promise.Promise) { |
214 |
| - filterResults.then(function(satisfies) { |
215 |
| - if (satisfies) { |
216 |
| - list.push(parentWebElements[index]); |
217 |
| - } |
218 |
| - }); |
219 |
| - } else if (filterResults) { |
220 |
| - list.push(parentWebElements[index]); |
221 |
| - } |
| 210 | + list.push(filterFn(elementFinder, index)); |
| 211 | + }); |
| 212 | + return webdriver.promise.all(list).then(function(resolvedList) { |
| 213 | + var filteredElementList = []; |
| 214 | + resolvedList.forEach(function(result, index) { |
| 215 | + if (result) { |
| 216 | + filteredElementList.push(parentWebElements[index]); |
| 217 | + } |
| 218 | + }); |
| 219 | + return filteredElementList; |
222 | 220 | });
|
223 |
| - return list; |
224 | 221 | });
|
225 | 222 | };
|
226 | 223 | return new ElementArrayFinder(this.ptor_, getWebElements, this.locator_);
|
@@ -533,11 +530,9 @@ ElementArrayFinder.prototype.map = function(mapFn) {
|
533 | 530 | arr.forEach(function(elementFinder, index) {
|
534 | 531 | var mapResult = mapFn(elementFinder, index);
|
535 | 532 | // All nested arrays and objects will also be fully resolved.
|
536 |
| - webdriver.promise.fullyResolved(mapResult).then(function(resolved) { |
537 |
| - list.push(resolved); |
538 |
| - }); |
| 533 | + list.push(webdriver.promise.fullyResolved(mapResult)); |
539 | 534 | });
|
540 |
| - return list; |
| 535 | + return webdriver.promise.all(list); |
541 | 536 | });
|
542 | 537 | };
|
543 | 538 |
|
@@ -637,10 +632,10 @@ ElementArrayFinder.prototype.allowAnimations = function(value) {
|
637 | 632 | *
|
638 | 633 | * The ElementFinder can be treated as a WebElement for most purposes, in
|
639 | 634 | * particular, you may perform actions (i.e. click, getText) on them as you
|
640 |
| - * would a WebElement. ElementFinders extend Promise, and once an action |
641 |
| - * is performed on an ElementFinder, the latest result from the chain can be |
642 |
| - * accessed using then. Unlike a WebElement, an ElementFinder will wait for |
643 |
| - * angular to settle before performing finds or actions. |
| 635 | + * would a WebElement. Once an action is performed on an ElementFinder, the |
| 636 | + * latest result from the chain can be accessed using the then method. |
| 637 | + * Unlike a WebElement, an ElementFinder will wait for angular to settle before |
| 638 | + * performing finds or actions. |
644 | 639 | *
|
645 | 640 | * ElementFinder can be used to build a chain of locators that is used to find
|
646 | 641 | * an element. An ElementFinder does not actually attempt to find the element
|
@@ -680,6 +675,28 @@ var ElementFinder = function(ptor, elementArrayFinder) {
|
680 | 675 | this.ptor_ = ptor;
|
681 | 676 | this.parentElementArrayFinder = elementArrayFinder;
|
682 | 677 |
|
| 678 | + // Only have a `then` method if the parent element array finder |
| 679 | + // has action results. |
| 680 | + if (this.parentElementArrayFinder.actionResults_) { |
| 681 | + /** |
| 682 | + * Access the underlying actionResult of ElementFinder. |
| 683 | + * |
| 684 | + * @param {function(webdriver.promise.Promise)} fn Function which takes |
| 685 | + * the value of the underlying actionResult. |
| 686 | + * |
| 687 | + * @return {webdriver.promise.Promise} Promise which contains the results of |
| 688 | + * evaluating fn. |
| 689 | + */ |
| 690 | + this.then = function(fn, errorFn) { |
| 691 | + return this.elementArrayFinder_.then(function(actionResults) { |
| 692 | + if (!fn) { |
| 693 | + return actionResults[0]; |
| 694 | + } |
| 695 | + return fn(actionResults[0]); |
| 696 | + }, errorFn); |
| 697 | + }; |
| 698 | + } |
| 699 | + |
683 | 700 | // This filter verifies that there is only 1 element returned by the
|
684 | 701 | // elementArrayFinder. It will warn if there are more than 1 element and
|
685 | 702 | // throw an error if there are no elements.
|
@@ -717,7 +734,6 @@ var ElementFinder = function(ptor, elementArrayFinder) {
|
717 | 734 | };
|
718 | 735 | });
|
719 | 736 | };
|
720 |
| -util.inherits(ElementFinder, webdriver.promise.Promise); |
721 | 737 |
|
722 | 738 | exports.ElementFinder = ElementFinder;
|
723 | 739 |
|
@@ -770,25 +786,6 @@ ElementFinder.prototype.getWebElement = function() {
|
770 | 786 | return new webdriver.WebElementPromise(this.ptor_.driver, id);
|
771 | 787 | };
|
772 | 788 |
|
773 |
| -/** |
774 |
| - * Access the underlying actionResult of ElementFinder. Implementation allows |
775 |
| - * ElementFinder to be used as a webdriver.promise.Promise |
776 |
| - * |
777 |
| - * @param {function(webdriver.promise.Promise)} fn Function which takes |
778 |
| - * the value of the underlying actionResult. |
779 |
| - * |
780 |
| - * @return {webdriver.promise.Promise} Promise which contains the results of |
781 |
| - * evaluating fn. |
782 |
| - */ |
783 |
| -ElementFinder.prototype.then = function(fn, errorFn) { |
784 |
| - return this.elementArrayFinder_.then(function(actionResults) { |
785 |
| - if (!fn) { |
786 |
| - return actionResults[0]; |
787 |
| - } |
788 |
| - return fn(actionResults[0]); |
789 |
| - }, errorFn); |
790 |
| -}; |
791 |
| - |
792 | 789 | /**
|
793 | 790 | * Calls to {@code all} may be chained to find an array of elements within a
|
794 | 791 | * parent.
|
@@ -957,17 +954,6 @@ ElementFinder.prototype.allowAnimations = function(value) {
|
957 | 954 | return this.elementArrayFinder_.allowAnimations(value).toElementFinder_();
|
958 | 955 | };
|
959 | 956 |
|
960 |
| -/** |
961 |
| - * Webdriver relies on this function to be present on Promises, so adding |
962 |
| - * this dummy function as we inherited from webdriver.promise.Promise, but |
963 |
| - * this function is irrelevant to our usage |
964 |
| - * |
965 |
| - * @return {boolean} Always false as ElementFinder is never in pending state. |
966 |
| - */ |
967 |
| -ElementFinder.prototype.isPending = function() { |
968 |
| - return false; |
969 |
| -}; |
970 |
| - |
971 | 957 | /**
|
972 | 958 | * Shortcut for querying the document directly with css.
|
973 | 959 | *
|
|
0 commit comments