Visual Studio FAQ: Why a Coded UI Test Is Able to Find the Window/Controls Even if the Search Properties Are Different

Visual Studio FAQ: Why a Coded UI Test Is Able to Find the Window/Controls Even if the Search Properties Are Different

Introduction

This is a common question that rises in the mind of every test developer.

Scenario

  • You add a control to UIMap using Coded UI Test Builder (You are able to locate the control using Coded UI Test Builder/Coded UI Test Editor; Control property P1 has value V1).
  • The control in UIMap has property P1 and its value V1.
  • Now either the actual properties of the control or the search properties in UIMap are changed (Either actual value of P1 changes to P2 or value of property P1 changes to P2 in UIMap).
  • Actual properties of control such as Window Title/Name or Control Id/Name are changed in the application. Or
  • You manually change the search properties of the control in UIMap using Coded UI Test Editor.
  • You again execute the Coded UI Test.
  • Coded UI Test is able to identify the Window/Control even if either actual properties or search properties in UIMap have changed and no longer match with the corresponding Search/Actual properties.
  • Test Developer wonders why?

Reason

The answer resides in the resilient playback support of the Coded UI Test Record and Playback Engine.
The Record and Playback Engine recognizes controls on the user interface by its search properties. Several search properties may perhaps alter over phase. Record and Playback engine makes use of a Smart Match algorithm to identify windows/controls if they cannot be sited using the exact properties. The smart match algorithm exercise heuristics and try to locate the window/control using variations on the search properties. This is what happens when the Playback is able find the window or control even after one or more search properties have changed. The Record and Playback Engine utilize this algorithm and identifies the window and/or control...

Solution

You can dodge this behavior by manipulating when Smart Match should be applied. By default Smart Match is applied for Top Level Windows and all controls. You can turn off Smart match in cases where you would like only exact matches by means of the following code snippet:

 

Note

The default setting (Smart match top level windows and controls) is most favorable for a resilient coded UI test. However occasionally it may lead to false positives and then you will have to adjust this setting.

See Also

 

Leave a Comment
  • Please add 4 and 8 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 7. Comment: Removed tags  "Microsoft Visual Studio 2010" and "MS", added tag "See Also", changed tag "VS 2010" to "Visual Studio 2010"

  • Richard Mueller edited Revision 6. Comment: Remove blank headings in HTML to fix TOC

  • Ed Price - MSFT edited Revision 5. Comment: Updated headers to H1

  • Ed Price - MSFT edited Revision 3. Comment: Title guidelines and tags. Some formatting. The title didn't have the technology/product in it.  

  • TejasJ edited Revision 2. Comment: Added links

  • TejasJ edited Original. Comment: Justify

Page 1 of 1 (6 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • TejasJ edited Original. Comment: Justify

  • TejasJ edited Revision 2. Comment: Added links

  • Ed Price - MSFT edited Revision 3. Comment: Title guidelines and tags. Some formatting. The title didn't have the technology/product in it.  

  • Ed Price - MSFT edited Revision 5. Comment: Updated headers to H1

  • Richard Mueller edited Revision 6. Comment: Remove blank headings in HTML to fix TOC

  • Richard Mueller edited Revision 7. Comment: Removed tags  "Microsoft Visual Studio 2010" and "MS", added tag "See Also", changed tag "VS 2010" to "Visual Studio 2010"

Page 1 of 1 (6 items)