[英]Unique identifiers for ui automation
Our ui automation team is asking for a better way to select elements for their automated tests. 我们的ui自动化团队正在寻求一种更好的方法来为自动化测试选择元素。 My thinking is that we can inject a dedicated attribute (say "ui-auto") for each testable element.
我的想法是我们可以为每个可测试元素注入一个专用属性(比如说“ui-auto”)。 This attribute would have a value which is:
此属性的值为:
My questions are: 我的问题是:
I should mention that we are using angular and I thought that using some kind of directive and/or service would help automate this. 我应该提到我们正在使用angular,我认为使用某种指令和/或服务可以帮助自动化。
I should also say that I don't want to use the "id" attribute b/c I'd like to have separation between development concerns (ids may be used for javascript), and qa concerns (selection of elements for automated tests) 我还应该说我不想使用“id”属性b / c我想在开发问题之间分离(id可以用于javascript),qa关注(选择自动测试的元素)
In our implementation we add to the DOM element a data-awt attribute, the value consists of a context (page and mode) type and unique string. 在我们的实现中,我们向DOM元素添加了一个data-awt属性,该值由上下文(页面和模式)类型和唯一字符串组成。 As we use the EXTJS library our type is the xtype and the unique string is components name or text property.
当我们使用EXTJS库时,我们的类型是xtype,唯一的字符串是组件名称或文本属性。 The context is developer controlled by placing a unique property on the upper most parent and all children use this as their context.
上下文是开发人员通过在最上面的父项上放置一个唯一属性来控制的,所有子项都使用它作为它们的上下文。
In practice we end up with data-awt values like devicesListing-button-edit, deviceDetails-displayfield-name, deviceDetailsEditWindow-textfield-name. 在实践中,我们最终得到数据awt值,如devicesListing-button-edit,deviceDetails-displayfield-name,deviceDetailsEditWindow-textfield-name。
We found that relying on css, id, or other attributes aren't reliable and predictable since we don't want to rewrite our tests whenever there is some UI change. 我们发现依赖于css,id或其他属性是不可靠和可预测的,因为我们不想在有任何UI更改时重写我们的测试。 Now the test only needs updating if an existing element changes its name (for example the PM says the name field should now use the 'customer' data from the DTO).
现在,如果现有元素更改其名称,则测试仅需要更新(例如,PM表示名称字段现在应该使用来自DTO的“客户”数据)。
You can also use the class of the element and provide a unique identifier prefixed with something like "auto_" or "t_". 您还可以使用元素的类,并提供前缀为“auto_”或“t_”之类的唯一标识符。
The agreement exists that if anyone changes the class name with that prefix, tests will break. 该协议存在,如果任何人用该前缀更改类名,测试将中断。
@o4ohel I agree that not using ids is better as devs also depend on them and they need to change sometimes. @ o4ohel我同意不使用id更好,因为开发人员也依赖于他们,他们有时需要改变。 Identifiers for automation should be isolated.
应该隔离自动化的标识符。 It's nice to have that separation.
有这种分离是很好的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.