Cloning element finders

拟墨画扇 提交于 2019-12-12 11:34:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!