问题描述
具有基类,它具有属性,可用于存储任意字符串。我正在尝试从Visual Studio 2010中获取该属性,基类,。
The UI Automation framework has a base class, AutomationElement, that has a property, ItemStatus, that can be used to store arbitrary strings. I'm trying to get that property from the Visual Studio 2010 Coded UI Tests base class, UITestControl.
推荐答案
查看编码的UI测试为<$ c生成的代码$ c> WpfControl 。它具有属性NativeElement。此属性是 AutomationElement
。
Look at the Coded UI Tests generated code for WpfControl
. It has a property, NativeElement. This property is an AutomationElement
.
public abstract class WpfControl : UITestControl
{
...
public virtual object NativeElement
{
get
{
return ((object)(this.GetProperty(UITestControlProperties.Common.NativeElement)));
}
}
...
}
您可以编写扩展方法来强制转换并获取ItemStatus。
You can write an extension method to cast it and get ItemStatus.
public static string GetItemStatus(this WpfControl control)
{
var automationElement = (AutomationElement)control.NativeElement;
return automationElement.Current.ItemStatus;
}
我不确定为什么NativeElement被记录为对象
(这会使getter变得多余)。所有WPF控件的NativeElement的类型为 AutomationElement
。我建议编辑生成的代码,然后直接调用 control.NativeElement.Current.ItemStatus
。
I am not certain why NativeElement is recorded as an object
(which makes the getter cast redundant). All WPF controls' NativeElement are of type AutomationElement
. I would suggest editing the generated code and simply calling control.NativeElement.Current.ItemStatus
directly.
这篇关于如何从UITestControl获取ItemStatus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!