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

Commit 50f44f4

Browse files
committed
feat(protractor): add clone methods for ElementFinder and ElementArrayFinder
1 parent 1e22226 commit 50f44f4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/protractor.js

+24
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ var buildElementHelper = function(ptor) {
142142
};
143143
util.inherits(ElementArrayFinder, webdriver.promise.Promise);
144144

145+
/**
146+
* Create a shallow copy of ElementArrayFinder.
147+
*
148+
* @return {!ElementArrayFinder} A shallow copy of this.
149+
*/
150+
ElementArrayFinder.prototype.clone = function() {
151+
// A shallow copy is all we need since the underlying fields can never be
152+
// modified. (Locator can be modified by the user, but that should
153+
// rarely/never happen and it doesn't affect functionalities).
154+
return new ElementArrayFinder(
155+
this.getWebElements, this.locator_, this.actionResults_);
156+
};
157+
145158
/**
146159
* Calls to ElementArrayFinder may be chained to find an array of elements
147160
* using the current elements in this ElementArrayFinder as the starting point.
@@ -722,6 +735,17 @@ var buildElementHelper = function(ptor) {
722735
};
723736
util.inherits(ElementFinder, webdriver.promise.Promise);
724737

738+
/**
739+
* Create a shallow copy of ElementFinder.
740+
*
741+
* @return {!ElementFinder} A shallow copy of this.
742+
*/
743+
ElementFinder.prototype.clone = function() {
744+
// A shallow copy is all we need since the underlying fields can never be
745+
// modified
746+
return new ElementFinder(this.parentElementArrayFinder);
747+
};
748+
725749
/**
726750
* See ElementArrayFinder.prototype.locator
727751
* @return {webdriver.Locator}

0 commit comments

Comments
 (0)