【问题标题】:How do I get ItemStatus from a UITestControl?如何从 UITestControl 获取 ItemStatus?
【发布时间】:2010-12-23 08:51:53
【问题描述】:

UI Automation framework 有一个基类AutomationElement,它有一个属性ItemStatus,可用于存储任意字符串。我正在尝试从 Visual Studio 2010 Coded UI Tests 基类 UITestControl 获取该属性。

【问题讨论】:

    标签: wpf ui-automation coded-ui-tests


    【解决方案1】:

    查看 Coded UI Tests 为 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(这使得 getter 演员变得多余)。所有 WPF 控件的 NativeElement 都是 AutomationElement 类型。我建议编辑生成的代码并直接调用control.NativeElement.Current.ItemStatus

    【讨论】:

      猜你喜欢
      • 2010-12-23
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 2021-05-16
      • 2019-08-25
      相关资源
      最近更新 更多