Configure search properties used by recordercode generation

This blog post has been updated to reflect changes in VS 2010 RC or later build.  If you are on VS 2010 Beta 2, please upgrade before trying this post. 

One question that keeps coming up is “How to configure search properties used by the recorder\code generation for identifying the control?”. For example, inform recorder that the Name of the certain control is dynamic and not to use it to identify the control.

Well, this feature per say is missing in VS 2010 release of Coded UI Test. However, there is a fairly simple workaround to this issue using the extensibility support of Coded UI Test.  The configuring search properties may mean add or remove or change of search properties.  Using the extensibility support, remove and change of search properties is possible but not add (unless you know the property value too).

The extensibility sample for this is attached to this post as

Before starting with this sample, ensure you have read at least the first two post on Coded UI Test Extensibility series.

Explaining the Sample -

  1. The sample hooks into UITest.Saving event.  This event is raised before the UITest file is saved and code is generated for it.

  2. It then iterates through all the UI objects.  The UI objects are stored in an hierarchical tree. The sample uses recursion to do pre-order traversal of the tree.  (Check for the calls to RemoveUnwantedSearchCondition() method.)

  3. During traversal, for each UI object, it calls GetRedundantSearchProperties() method in the sample. Based on the property names returned by this method, it removes those properties, if present, from the UI object’s search criteria.

  4. The current implementation of GetRedundantSearchProperties() method simply removes “Name” property for all but few Win32\WinForms control from the search criteria.  Depending on your need, you can customize this function accordingly.

Please note that since the sample is removing a search property, it might make the search criteria weak and result in playback failure.  This is the reason for “claiming” this only a “workaround”.

Comments (11)

  1. BuckTheBug says:


    what VS2010 version I need to use your example? RC? It seems namespace ‘CodeGeneration’ doesn’t exist in Beta 2. 🙁


  2. Hi Buck,

    The sample is for Beta 2 only.  The possibility could be that some reference is not resolved properly. Check for any warning in the reference particularly Microsoft.VisualStudio.TeamTest.UITest.CodeGeneration.dll.  You might have to fix the path to this dll.


  3. BuckTheBug says:

    Hi, you’re right. Thanks. 🙂

  4. Great content! The extensibility series totally rocks!

    I wish the comments on some of the older posts were still enabled for folks to ask qs on relevant posts. Is there a reason you want to close commenting on older posts?

  5. Anu – All the posts are open to commenting.  I have not done anything deliberate to block comments.

  6. SHANMUGAVEL.C says:

    Hi Gautam,

    I need help on using separate UIMAP.uitest files… Here is my scenario.

    1) I have created a new folder "Screen1" under my project "TSApp".

    2) I added new CodedUI test by right-cliking "Screen1" folder –> "Screen1TEST.cs"

    3) then added new CodedUIMap item by right-cliking "Screen1" folder –> "Screen1UIMAP.uitest" and recorded some actions –> saved as "Method_Add". Here it created "Screen1UIMAP.cs" and "Screen1UIMAP.Designer.cs" files

    4) then i went to "Screen1TEST.cs" file and trying to call recorded "Method_Add" as


    but here it not listing out this "Screen1UIMAP" file under TSApp.Screen1..

    Anything i went wrong?  Can u give me an idea on this…OR

    Tell me the approach to use separate UIMAP file and creating TEST based on that…

    Thanks in advance,


  7. Please use Coded UI Test forum –…/threads for such questions.


  8. subbu says:

    thanks for the great Post; i am trying this for my project to customize href;Pageurl ; but not sure if i got this even though i have copied this demo to the required folder still not getting desired , any help how can i debug this ?

  9. @subbu – What is the error that you are seeing? Note that the path to copy the files are different on 32bit machine vs 64 bit machine.  Check for details in…/2-hello-world-extension-for-coded-ui-test.aspx.

    Try the above Hello, World plugin to see if you are able to get that working.

  10. Tester says:

    Hi Guatam,

    Can you elaborate some more on "Using the extensibility support, remove and change of search properties is possible but not add (unless you know the property value too)."?  I was having trouble with CUIT recognizing some MFC controls after receiving a new test build.

    I want to help CUIT find the controls with perhaps adding search properties.  Most likely this will need to be done by hand coding and not recording.  Can you point me in the right direction?

    Thanks in advance.

  11. The above extensibility hook is during saving of the generated file.  Hence it can only remove (or make certain changes) to the properties captured by the recorder.  To add properties, we need a hook into the recorder to ask it to capture the properties in first place which is not there today.


Skip to main content