我正在尝试在编写Coded UI测试时使用自定义控件属性,但我找到的所有示例都毫无用处。
例如:http://msdn.microsoft.com/en-us/library/hh552522.aspx
如果您有两个不同的控件是“文本”控件,那么这段代码完全没有用处-无法确定它是哪种类型的文本控件。 “ControlType”属性非常具有误导性,因为它并不像其名称所暗示的那样返回控件的类型。它更像是一个控件类别。您如何确定实际的控件类型?
例如:http://msdn.microsoft.com/en-us/library/hh552522.aspx
public override int GetControlSupportLevel(UITestControl uiTestControl)
{
// For MSAA, check the control type
if (string.Equals(uiTestControl.TechnologyName, "MSAA",
StringComparison.OrdinalIgnoreCase) &&
(uiTestControl.ControlType == "Chart"||uiTestControl.ControlType == "Text"))
{
return (int)ControlSupport.ControlSpecificSupport;
}
// This is not my control, so return NoSupport
return (int)ControlSupport.NoSupport;
}
// Get the property value by parsing the accessible description
public override object GetPropertyValue(UITestControl uiTestControl, string propertyName)
{
if (String.Equals(propertyName, "State", StringComparison.OrdinalIgnoreCase))
{
object[] native = uiTestControl.NativeElement as object[];
IAccessible acc = native[0] as IAccessible;
string[] descriptionTokens = acc.accDescription.Split(new char[] { ';' });
return descriptionTokens[1];
}
// this is not my control
throw new NotSupportedException();
}
如果您有两个不同的控件是“文本”控件,那么这段代码完全没有用处-无法确定它是哪种类型的文本控件。 “ControlType”属性非常具有误导性,因为它并不像其名称所暗示的那样返回控件的类型。它更像是一个控件类别。您如何确定实际的控件类型?