CodedUI如何将值传递给treeItem [英] CodedUI How to pass values to a treeItem

查看:48
本文介绍了CodedUI如何将值传递给treeItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的winform应用程序中,有一个BrowseForFolder窗口。在记录测试方法时,我选择说 C:\Folder1\MyData 。但是,此路径可能不同,我正在编写一个以driveLetter,文件夹名和文件名为参数的方法。这些值应该是在浏览器窗口中选择的值。当我查看UIMap时,有树项。

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.

例如,对于驱动器名称,其 UILocalDiskCTreeItem 。搜索属性具有以下内容:

For instance, for drive name, its UILocalDiskCTreeItem. Search properties has the following:

ControlType: TreeItem
Name: Local Disk (C:)
Value 2 (denotes the depth)

我尝试将此树项的Name / Friendly Name属性设置为D使用

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?

推荐答案

在UI Map编辑器中打开UI Map(这是标准配置的一部分) Visual Studio 2012,已在功能包2中添加到Visual Studio 2010中)。在右侧窗格中找到相关的UI控件,然后打开其属性面板。选择搜索属性过滤器属性,然后单击该属性的省略号。现在,您应该有一个窗口,其中提供了用于搜索控件的各种项目,并可以根据需要进行编辑。

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.

另一种可能性是在使用它们之前通过代码更改它们。在调用记录的操作之前的 Codeduitest1.cs文件中,声明 UITestControl 并将其初始化为 this.UIBrowseForFolderWindow.UITreeViewWindow.UIDesktopTreeItem .UIComputerTreeItem ,然后更改其 SearchProperties FilterProperties 的内容。不知道您的代码的初始化值可能需要在Heirachy中更高或更低。

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.UIComputerTreeIt‌em
        .UILocalDiskCTreeItem.UISTreeItem;

    control1.SearchProperties.Add(WinControl.PropertyNames.Name,
        folderName, PropertyExpressionOperator.Contains);

    Mouse.Click(control1);
}

这篇关于CodedUI如何将值传递给treeItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆