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