In my winform application, there's a BrowseForFolder window. While recording a test method, I selected say C:\Folder1\MyData
. However this path can be different and I am writing a method which takes the driveLetter, foldername and filename as parameters. These values should be the ones selected in the browserwindow. When I looked at the UIMap, there are treeitems.
For instance, for drive name, its UILocalDiskCTreeItem
. Search properties has the following:
ControlType: TreeItem
Name: Local Disk (C:)
Value 2 (denotes the depth)
I tried setting the Name/Friendly Name property of this tree item to D drive using
this.UIBrowseForFolderWindow.UITreeViewWindow.UIDesktopTreeItem.UIComputerTreeItem.UILocalDiskCTreeItem.SetProperty("Friendly Name", "D:")
However name appears to be read only property and friendly name is also not working. How to pass the selection value to the tree item?
Open the UI Map in the UI Map editor (a standard part of Visual Studio 2012, added to Visual Studio 2010 in Feature Pack 2). Find the relevant UI Control in the right hand pane and open its properties panel. Select Search properties or Filter properties and then click on the ellipsis for that property. You should now have a window giving the various items that are used to search for the control and can edit them as needed.
I recommend doing the above even if only to see how the properties are built up.
Another possibility is to alter the properties by code before they are used. In the "Codeduitest1.cs" file just before the recorded action is called, declare a UITestControl
and initialise it to the this.UIBrowseForFolderWindow.UITreeViewWindow.UIDesktopTreeItem.UIComputerTreeItem
then alter the contents of its SearchProperties
or FilterProperties
. Not knowing your code the initialising value may need to be higher or lower in the heirachy.
Update. The questioner showed code that worked in a comment to this answer. That code is copied here so it is easier to read.
if (!String.IsNullOrEmpty(folderName))
{
UITestControl control1 = this.UIBrowseForFolderWindow
.UITreeViewWindow.UIDesktopTreeItem.UIComputerTreeItem
.UILocalDiskCTreeItem.UISTreeItem;
control1.SearchProperties.Add(WinControl.PropertyNames.Name,
folderName, PropertyExpressionOperator.Contains);
Mouse.Click(control1);
}