Freigeben über


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 RemoveUnwantedProperties.zip.

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”.

RemoveUnwantedProperties.zip

Comments

  • Anonymous
    February 02, 2010
    Hi, what VS2010 version I need to use your example? RC? It seems namespace 'CodeGeneration' doesn't exist in Beta 2. :( Thanks.

  • Anonymous
    February 02, 2010
    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. Thanks.

  • Anonymous
    February 02, 2010
    Hi, you're right. Thanks. :)

  • Anonymous
    February 04, 2010
    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?

  • Anonymous
    February 05, 2010
    Anu - All the posts are open to commenting.  I have not done anything deliberate to block comments.

  • Anonymous
    August 26, 2010
    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 TSApp.Screen1.Screen1UIMAP.Method_Add() 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, Shanmugavel.
  • Anonymous
    August 26, 2010
    Please use Coded UI Test forum - social.msdn.microsoft.com/.../threads for such questions. Thanks.

  • Anonymous
    January 06, 2011
    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 ?

  • Anonymous
    January 09, 2011
    @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 blogs.msdn.com/.../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.

  • Anonymous
    March 24, 2011
    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.

  • Anonymous
    April 06, 2011
    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. Thanks.