2013-10-31 115 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();