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

Commit

Permalink
chore(element.js): Moved webdriver element specific methods into prot…
Browse files Browse the repository at this point in the history
…otype
  • Loading branch information
stalniy authored and sjelin committed Nov 9, 2015
1 parent 3bd5828 commit deba67d
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,20 @@ var ElementArrayFinder = function(ptor, getWebElements, locator, opt_actionResul
this.getWebElements = getWebElements || null;
this.actionResults_ = opt_actionResults;
this.locator_ = locator;

var self = this;
WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
self[fnName] = function() {
var args = arguments;
var actionFn = function(webElem) {
return webElem[fnName].apply(webElem, args);
};
return self.applyAction_(actionFn);
};
});
};

exports.ElementArrayFinder = ElementArrayFinder;

WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
ElementArrayFinder.prototype[fnName] = function() {
var args = arguments;
var actionFn = function(webElem) {
return webElem[fnName].apply(webElem, args);
};
return this.applyAction_(actionFn);
};
});

/**
* Create a shallow copy of ElementArrayFinder.
*
Expand Down Expand Up @@ -692,16 +691,6 @@ var ElementFinder = function(ptor, elementArrayFinder) {
this.elementArrayFinder_ = new ElementArrayFinder(
this.ptor_, getWebElements, elementArrayFinder.locator_,
elementArrayFinder.actionResults_);

// Decorate ElementFinder with webdriver functions. Simply calls the
// underlying elementArrayFinder to perform these functions.
var self = this;
WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
self[fnName] = function() {
return self.elementArrayFinder_[fnName].
apply(self.elementArrayFinder_, arguments).toElementFinder_();
};
});
};

exports.ElementFinder = ElementFinder;
Expand All @@ -714,6 +703,13 @@ ElementFinder.fromWebElement_ = function(ptor, webElem, locator) {
toElementFinder_();
};

WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
ElementFinder.prototype[fnName] = function() {
return this.elementArrayFinder_[fnName].
apply(this.elementArrayFinder_, arguments).toElementFinder_();
};
});

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

0 comments on commit deba67d

Please sign in to comment.