The UI自动化框架 http://msdn.microsoft.com/en-us/library/ms747327.aspx有一个基类,自动化元件 http://msdn.microsoft.com/en-us/library/system.windows.automation.automationelement.aspx,有一个属性,项目状态 http://msdn.microsoft.com/en-us/library/system.windows.automation.automationproperties.itemstatus%28VS.100%29.aspx,可用于存储任意字符串。我正在尝试从 Visual Studio 2010 获取该属性编码 UI 测试 http://msdn.microsoft.com/en-us/library/dd286726%28VS.100%29.aspx基类,UI测试控件 http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.uitestcontrol%28VS.100%29.aspx.
查看编码的 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
(这使得 getter 强制转换变得多余)。所有 WPF 控件的 NativeElement 都是类型AutomationElement
。我建议编辑生成的代码并简单地调用control.NativeElement.Current.ItemStatus
直接地。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)