TreeItem中的每个UIElement在SearchProperties中都有一个'Value'属性。此值似乎具有深度,例如“我的电脑”的值为1,“我的电脑”中的某个文件夹的值为2,依此类推。我正在尝试修改我的代码以动态定位文件夹名称。为此,我尝试将name属性和value属性作为搜索属性传递。但WinControl.PropertyNames.Value不存在。我可以做点像
con.SearchProperties.Add(WinControl.PropertyNames.Name,folderName [ii],PropertyExpressionOperator.Contains))。
UserInput可以是:C:\ folder1 \ folder2 \ folder3或C:\ folder1 \ folder2
根据用户输入中的文件夹数量,需要遍历treeItem。我正在尝试做类似
的事情string path = "C:\folder1\folder2\folder3";
string[] folderNames = path.Split("\\");
string driveLetter = folderNames[0];
for (int index=1; index < folderNames.Length; index++)
{
UITestControl locateTreeItem = this.UIBrowseForFolderWindow.UITreeViewWindow.UIDesktopTreeItem.UIComputerTreeItem; //Points to My Computer
locateTreeItem.SearchProperties.Add(WinControl.PropertyNames.Name, folderName[index], PropertyExpressionOperator.Contains);
locateTreeItem.SearchProperties.Add(WinControl.PropertyNames.Value, index+1, PropertyExpressionOperator.Equals);
Mouse.Click(locateTreeItem);
}
然而似乎没有WinControl.PropertyNames.Value这样的选项。我得到compileTime错误'Microsoft.VisualStudio.TestTools.UITesting.WinControls.WinControl.PropertyNames'不包含'Value'的定义。但是,此属性显示在“编辑搜索属性”窗口中,以显示treeItem以及Name,ControlType等。
答案 0 :(得分:1)
如果你仔细看看UITestControl.SearchProperties.Add,你会发现它需要字符串作为参数,所以你只需输入... Add(“Value”,(index + 1).ToString() )
这也适用于您遇到的几乎所有SetValue和GetValue函数。 (编辑2:想到它,那些主要是类型对象而不是字符串,对不起)
或者,如果您查看UIMap.Designer.cs中生成的TreeItems代码,它看起来像UITestControl.SearchProperties [“Value”] =“0”。所以你也可以使用locateTreeItem.SearchProperties [“Value”] =(index + 1).ToString()
编辑:您还应该考虑在创建测试控件时包含树层次结构。像这样:
string path = @"C:\Windows\Boot\PCAT\hu-HU";
string[] folderNames = path.Split('\\');
WinTreeItem ParentTreeItem = this.UIMap.UIComputerWindow.UITreeViewWindow.UITreeViewTree.UIDesktopTreeItem.UIComputerTreeItem;
int Depth = int.Parse(ParentTreeItem.SearchProperties["Value"]) + 1;
for (int index = 0; index < folderNames.Length; index++)
{
WinTreeItem TreeItem = new WinTreeItem(ParentTreeItem);
if (index == 0)
TreeItem.SearchProperties["Name"] = string.Format("Local Disk ({0})", folderNames[0]);
else
TreeItem.SearchProperties["Name"] = folderNames[index];
TreeItem.SearchProperties["Value"] = Depth.ToString();
++Depth;
TreeItem.SearchConfigurations.Add(SearchConfiguration.NextSibling);
TreeItem.SearchConfigurations.Add(SearchConfiguration.ExpandWhileSearching);
ParentTreeItem = TreeItem;
}
Mouse.Click(ParentTreeItem);
答案 1 :(得分:0)
我在get函数中为Parent和Child树项提供了Value属性,如下所示:
//In the Get Function of the Parent Tree Item
int Depth = 3 //This is what it shows for Value property when I use the crosshair tool for Parent tree item
ParentTreeItem.SearchProperties["Value"] = Depth.ToString();
//In the Get Function of the Child Tree Item
int Depth = 4 //This is what it shows for Value property when I use the crosshair tool for Child tree item
ChildTreeItem.SearchProperties["Value"] = Depth.ToString();