Content of the post
AutomationId : what is it ?^ As stated in the previous post, an application exposes AutomationPeer. They are then found by UI Automation Client as AutomationElement objects. These items are identified uniquely by the AutomationId property. This identifier is not mandatory but it’s a best practice to set it when you plan to perform UI tests.To retrieve a control, the automation peer tree is used : first the top element is found, then the automation client iterate on its children, then the children of the children until it finds the aimed element. Each of the children and the final target is find using conditions and usually, one is set on the automation id. The automation id is a property which helps you to find a specific UI element among others. This is, for example, very useful when you want to find a specific item in a collection (listbox, menus, etc.). Another benefit is that, as the control is uniquely identified, you can move it elsewhere or change its name and it will still be found by a previous code needing it. To leverage the power of it, there is a rule to respect: it’s expected to be the same in any instance of the same application and ‘unique by instance in its scope‘. If you exit the application and launch it again, the value will not change.
If you change the culture of the PC/Application, it will not change.
If you launch several instance of the application, it remains the same on each of them.
If there is several usage of the control in the application, each of them has a different automation id on each scope. A scope is defined by the path in the tree to go to the element. For example each menu item of a menu can be named in a generic way : menuItem1, menuItem2, etc. This is a rule and you are not forced by the runtime or anything to follow it. As a proof, AutomationPeer returns a default value of string.empty which is really not unique!By the way, if you want to set a name to a control(for example to improve accesibility) uses the Name property instead of the AutomationId one. Read more: Yet another blog about…
QR:
- AutomationId : what is it ?
- How to set it ?
- How to use it in automation clients ?
- How is it used by the Coded UI tests builder ?
- How to find it on existing application ?
- When to set the AutomationId ?
- AutomationId and ItemsControl or dynamically generated controls.
- More to read on the subject
AutomationId : what is it ?^ As stated in the previous post, an application exposes AutomationPeer. They are then found by UI Automation Client as AutomationElement objects. These items are identified uniquely by the AutomationId property. This identifier is not mandatory but it’s a best practice to set it when you plan to perform UI tests.To retrieve a control, the automation peer tree is used : first the top element is found, then the automation client iterate on its children, then the children of the children until it finds the aimed element. Each of the children and the final target is find using conditions and usually, one is set on the automation id. The automation id is a property which helps you to find a specific UI element among others. This is, for example, very useful when you want to find a specific item in a collection (listbox, menus, etc.). Another benefit is that, as the control is uniquely identified, you can move it elsewhere or change its name and it will still be found by a previous code needing it. To leverage the power of it, there is a rule to respect: it’s expected to be the same in any instance of the same application and ‘unique by instance in its scope‘. If you exit the application and launch it again, the value will not change.
If you change the culture of the PC/Application, it will not change.
If you launch several instance of the application, it remains the same on each of them.
If there is several usage of the control in the application, each of them has a different automation id on each scope. A scope is defined by the path in the tree to go to the element. For example each menu item of a menu can be named in a generic way : menuItem1, menuItem2, etc. This is a rule and you are not forced by the runtime or anything to follow it. As a proof, AutomationPeer returns a default value of string.empty which is really not unique!By the way, if you want to set a name to a control(for example to improve accesibility) uses the Name property instead of the AutomationId one. Read more: Yet another blog about…
QR:
0 comments:
Post a Comment