Partager via


Search Configuration–Expand While Searching

Coded UI Test playback behavior can be modified by several configurations. In this article, I will talk about a Search Configuration – Expand While Searching.

While playing back a Coded UI Test, the UI Test framework performs two key steps.

1. Search for the control

2. Perform actions on the control

 

Search is done based on the search properties we provide. The behavior of search can be modified by various search configurations.  Expand While Searching configuration is applicable for controls such as Tree and menu. To locate a leaf node inside a tree, UI Test Framework has to expand all the intermediate nodes from the leaf to its root.

 

Consider the following folder  item in Internet Explorer.

clip_image002

You need to ensure that Libraries & Pictures nodes are expanded before trying to locate My Pictures. UI Test Framework will do that for you if you specify Expand while searching configuration for both these controls.

 

Here is how the code for Pictures should look.

WinTreeItem uiPicturesTreeItem = new WinTreeItem(uiLibrariesTreeItem) ;

uiPicturesTreeItem.SearchProperties[WinTreeItem.PropertyNames.Name] = "Pictures";

uiPicturesTreeItem.SearchConfigurations.Add(SearchConfiguration.ExpandWhileSearching);

 

NOTE that if you use Coded UI Test Builder to record actions or Add the control using Coded UI Test Builder, this configuration is set by default.

 

We have seen several customers who are now using a pure hand-coding approach to authoring Coded UI Tests.  If you are using this pure hand-coding model, you need to ensure that Expand While Searching configuration is set for all expandable controls.