问题
While researching available ElementFinder
and ElementArrayFinder
methods, I've noticed that there is a clone() method which is briefly documented:
Create a shallow copy of ElementFinder.
From what I understand, clone()
is not coming from WebdriverJS
and is a protractor-specific function. What I don't understand is why would you want to clone an element finder or an element finder "array" in your tests? What use cases does clone()
cover?
I've looked into the protractor source code to find example usages, but found only the underlying change set, which didn't help to have a clear picture.
回答1:
Clone was introduced here: https://github.com/angular/protractor/issues/1303. And honestly now I think about it, it was a mistake to introduce it, as it offers no practical values.
Originally, there was fear that subsequent chains of elementFinders would affect previous ones:
var outerElement = element(by.abc...).all(by.def...).first().element(by.ghi...);
var outerText = outerElement.getText();
var innerElement = innerElement.element(by.xyz...);
// Now that I chained more things onto outerElement, is the original outerElement still behaving the same as before? (i.e. is outerText the same as outerElement.getText() still)
来源:https://stackoverflow.com/questions/29929848/cloning-element-finders