克隆元素查找器 [英] Cloning element finders
问题描述
在研究可用的 ElementFinder
和 ElementArrayFinder
方法时,我注意到有一个 clone()
方法 简要记录:
While researching available ElementFinder
and ElementArrayFinder
methods, I've noticed that there is a clone()
method which is briefly documented:
创建 ElementFinder 的浅表副本.
Create a shallow copy of ElementFinder.
据我所知,clone()
不是来自 WebdriverJS
而是一个量角器特定的函数.我不明白的是为什么要在测试中克隆元素查找器或元素查找器数组"?clone()
涵盖哪些用例?
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.
推荐答案
Clone 在这里介绍:https://github.com/angular/protractor/issues/1303.老实说,现在我想起来,引入它是错误的,因为它没有提供任何实用价值.
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.
最初,担心后续的 elementFinder 链会影响之前的链:
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)
这篇关于克隆元素查找器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!