[英]Identifying objects generated through framework and not built through raw HTML
I have a scenario where i am unable to identify some of my objects on page. 我有一个场景,我无法在页面上识别我的一些对象。 They don't have a unique identifier (like name, class, id).
它们没有唯一标识符(如name,class,id)。 Our Dev team uses a JS framework which generates models, views, controllers etc and assigns id's dynamically.
我们的开发团队使用JS框架生成模型,视图,控制器等,并动态分配id。 Also there are many children views which get dynamically generated with dynamic id's.
还有许多子视图,它们通过动态id动态生成。
So i cannot use id's as it changes. 所以我不能使用id的变化。 I don't want to use xpath as it is not the industry standard.
我不想使用xpath,因为它不是行业标准。 I tried css-selector but it gives me a long path not sure if that's a right way.
我尝试了css选择器,但它给了我一个很长的路径,不确定这是否是正确的方法。
I wanted to know from all of you, is it a right practice to add extra attributes to an object in the development code for testing purpose ? 我想从大家那里了解到,为了测试目的,在开发代码中为对象添加额外属性是否正确? Or is there any better way of handling these scenarios?
或者有更好的方法来处理这些情况吗?
If you're actually using SproutCore, you can easily add a classNames
( doc link ) or layerId
( doc link ) property to any view to make the CSS selectors shorter. 如果您实际使用SproutCore,则可以轻松地将
classNames
( doc link )或layerId
( doc link )属性添加到任何视图,以缩短CSS选择器。
For instance: 例如:
MyApp.MainListView = SC.ListView.extend({
layerId: 'my_special_view',
classNames: 'my-special-class',
content: ["Hi", "Foo", "Bar"],
exampleView: SC.ListItemView.extend({
classNames: 'my-special-list-class'
})
})
Note: You will want to only use the layerId
property if you're positive that there will only be 1 instance of the view on the screen, otherwise, the classNames
property is the better way to go. 注意:如果您肯定在屏幕上只有1个视图实例,那么您将只想使用
layerId
属性,否则, classNames
属性是更好的方法。
I would recommend adding some class names that are not testing specific, but that allow you to use shorter CSS selectors. 我建议添加一些不是特定测试的类名,但允许你使用更短的CSS选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.