2013-10-31 117 views
0

TreeItem中的每个UIElement在SearchProperties中都具有“Value”属性。此值似乎有深度,例如“我的电脑”的值为1,“我的电脑”中的某个文件夹的值为2,依此类推。我正在尝试修改我的代码以动态查找文件夹名称。为了做到这一点,我试图通过名称属性和值属性作为搜索属性。但WinControl.PropertyNames.Value不存在。我可以做类似CodedUI TreeItem更改值属性

con.SearchProperties.Add(WinControl.PropertyNames.Name,folderName [ii],PropertyExpressionOperator.Contains))。

UserInput可能是这样的:C:\ folder1中\文件夹2 \ folder3或C:\ folder1中\文件夹2

根据在用户输入的文件夹的数量,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以及Name,ControlType等。

回答

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); 
0

我给Value属性,如下图所示get函数的亲子树项目和它的工作:

//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();