简体   繁体   English

ui自动化的唯一标识符

[英]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: 此属性的值为:

  • unique 独特
  • persistent (doesn't change across sessions or page loads so as to not break the tests) 持久性(不会跨会话或页面加载而改变,以免破坏测试)
  • predictable (follows some naming convention depending on action type, location, etc.) 可预测的(遵循一些命名约定,具体取决于操作类型,位置等)

My questions are: 我的问题是:

  1. Is this a good idea? 这是一个好主意吗? better ideas are welcome. 欢迎更好的想法。
  2. Are there existing conventions for this? 现有惯例吗?
  3. What the best way to implement this? 实现这个的最佳方法是什么?

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.

相关问题 动态形式的唯一标识符(ng-repeat) - Unique identifiers in dynamic form (ng-repeat) 开发人员如何为Grid中的HTML控件分配可以由自动化测试工具(如代码UI)使用的HTML的唯一ID? - How developers can assign Unique Id for HTML Controls in Grid which can used by Automation Test tool like Code UI? 使用watir自动化在UI网格中输入文本 - Entering text into a UI-grid using watir automation Jasmine为什么期望量角器总是返回true(Web UI自动化测试) - Why did Jasmine expect always return true in protractor (Web UI Automation Test) 如何将唯一的ui-sref与动态列表中的每个项目相关联? - How to associate a unique ui-sref to every items in a dynamic list? 如何使用cellClass函数在UI Grid中突出显示唯一单元格? - How to highlight unique cell in UI Grid using cellClass function? 使用angular ui unique消除下拉​​菜单中的重复项 - eliminate duplicates in the drop down menu using angular ui unique 如何创建外观独特的ui引导对话框 - how do I create unique looking angular ui bootstrap dialogs Angular UI Select,预选数组的唯一值 - Angular UI Select, Unique values pre-selected array ui-grid行具有唯一的ID - ui-grid row to have unique id's
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM