In my last article on Coded UI Basic Walkthrough, we have seen the Record and Playback Mechanism of Coded UI. In this article I would like to discuss about the ‘Object Identification Mechanism of CodedUI’. How Coded UI identifies the objects present on the User Interface?
Each object has some search properties associated with it. Along with this, if the object’s Technology is Web then it also has Filter properties associated with it. Coded UI uses these properties to identify the objects at runtime.
Link of my last article - http://www.dotnetfunda.com/articles/article1241-coded-ui-test-basic-walkthrough-.aspx
Object’s Properties in CodedUI Test Editor
When some object is added using the Coded UI Test Builder and then generating the code using Generate Code button[right most in the below screenshot], Coded UI adds these objects in a file called UIMap(UIMap.uitest), Coded UI adds the exposed properties of the object as Search and Filter properties.
For more information on how to add objects using Coded UI, please refer to my previous article Coded UI Basic Walkthrough .
If you have Feature Pack 2 installed, you will be able to see the objects added in UIMap in CodedUI Test Editor. If you are a MSDN subscriber, you can install the Feature Pack 2 from http://msdn.microsoft.com/en-us/vstudio/ff655021
You can open the Test Editor by double clicking on the UIMap.uitest file present in the Solution Explorer, generated by Coded UI.
If you see the below screenshot, I am able to see the highlighted ‘UICloseDocumentTabButton’ in the UI Control Map.
Select the ‘Properties’ from context menu and you will see ‘Search Properties’ and ‘Filter Properties’ of the selected object in the Property Editor.
You can edit the object’s properties based on your requirements. E.g. if you know that object can be uniquely identified by its ‘Id’, you can remove all other Search and Filter properties. This will improve the performance of the CodedUI.
In case of Filter properties, the properties get checked one by one in the sequential order.
If object cannot be identified based on one filter property, then that property is ignored and Coded UI starts identifying the object based on the next filter property.
Object Identification Mechanism
During the Playback, Coded UI first searches for the object having all the specified search properties using ‘AND’ and then one by one it searches with filter properties using ‘OR’ and returns the resultant UI Object.
Search, then the first object satisfying the search would be returned.
Exceptions when property is not found
In case of, Search Property not found:
For Web Technology:
‘UITestControlNotFoundException’ will be thrown
For MSAA/UIA Technology:
‘System.ArgumentException’ will be thrown
In case of, Filter property not found, it is just ignored.
Best Practices in Object Identification for Performance Improvement
· Make the unique property as the ‘Search property’ of the object. And remove other Search and Filter properties.
· If there are some properties in ‘Filter Property’ which can help in identifying the object uniquely, make that property as a ‘Search Property’.
· Make prudent use of Search and Filter properties and Disable the Smart Match Identification.
Coded UI uses Search and Filter properties of an object for identifying it during the Playback.
Prudent use of these properties can improve the Coded UI performance and make the test automation stable for future.
If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.
Found interesting? Add this to: