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

Commit

Permalink
chore(protractor): speed up calls to then/each/map/reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Nov 6, 2014
1 parent 30023f2 commit 7240360
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ var buildElementHelper = function(ptor) {
return self.getWebElements().then(function(parentWebElements) {
var list = [];
parentWebElements.forEach(function(parentWebElement, index) {
var elementFinder = self.get(index); // Wrap in ElementFinder
var elementFinder =
ElementFinder.fromWebElement_(parentWebElement, self.locator_);

var filterResults = filterFn(elementFinder, index);
if (filterResults instanceof webdriver.promise.Promise) {
filterResults.then(function(satisfies) {
Expand Down Expand Up @@ -460,8 +462,8 @@ var buildElementHelper = function(ptor) {
var self = this;
return this.getWebElements().then(function(arr) {
var list = [];
arr.forEach(function(webElem, index) {
list.push(self.get(index));
arr.forEach(function(webElem) {
list.push(ElementFinder.fromWebElement_(webElem, self.locator_));
});
return list;
});
Expand Down Expand Up @@ -737,6 +739,14 @@ var buildElementHelper = function(ptor) {
};
util.inherits(ElementFinder, webdriver.promise.Promise);


ElementFinder.fromWebElement_ = function(webElem, locator) {
var getWebElements = function() {
return webdriver.promise.fulfilled([webElem]);
};
return new ElementArrayFinder(getWebElements, locator).toElementFinder_();
};

/**
* Create a shallow copy of ElementFinder.
*
Expand Down

0 comments on commit 7240360

Please sign in to comment.