UI自动化框架 有一个基类, 自动化元件, ,有一个属性, 项目状态, ,可用于存储任意字符串。我正在尝试从 Visual Studio 2010 获取该属性 编码 UI 测试 基类, UI测试控件.

有帮助吗?

解决方案

看的编码的UI测试生成WpfControl代码。它有一个属性,NativeElement。此属性是一个AutomationElement

public abstract class WpfControl : UITestControl
{
    ...

    public virtual object NativeElement
    {
        get
        {
            return ((object)(this.GetProperty(UITestControlProperties.Common.NativeElement)));
        }
    }

    ...
}

您可以编写扩展方法来投,并得到ItemStatus。

public static string GetItemStatus(this WpfControl control)
{
    var automationElement = (AutomationElement)control.NativeElement;
    return automationElement.Current.ItemStatus;
}

我不能肯定为什么NativeElement记录为object(这使得吸气剂浇铸冗余)。所有的WPF控件NativeElement的类型AutomationElement的。我建议编辑所生成的代码和简单地直接调用control.NativeElement.Current.ItemStatus

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top