0

TreeItem 中的每个 UIElement 在 SearchProperties 中都有一个“值”属性。此值似乎具有深度,例如我的电脑的值为 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”不包含“值”的定义。但是,此属性与名称、控件类型等一起显示在 treeItem 的编辑搜索属性窗口中。

4

2 回答 2

1

如果您仔细查看 UITestControl.SearchProperties.Add 您会注意到它以字符串作为参数,因此您只需键入 ...Add("Value", (index + 1).ToString())

这也适用于您遇到的几乎所有 SetValue 和 GetValue 函数。(Edit2:想一想,那些主要是对象类型而不是字符串,对不起)

或者,如果您查看 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);
于 2013-11-15T10:30:11.837 回答
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();
于 2013-11-18T16:10:19.930 回答