我为自定义控件编写了AutomationPeer类:
// Automation Peer for the CustomControl
private class CustommControlAutomationPeer : FrameworkElementAutomationPeer, IValueProvider, IGridProvider
{
public CustomControlAutomationPeer(CustomControl control)
: base(control)
{ }
#region overriding the "Core" methods from the base automation peer class that describe behavior unique and specific to custom control
...
#endregion
#region overriding of GetPattern should return the object that implements the specified pattern
public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.Grid || patternInterface == PatternInterface.Value)
{
return this;
}
return base.GetPattern(patternInterface);
}
#endregion
#region IGridProvider
...
#endregion
#region IValueProvider
...
#endregion
/// <summary>
/// Pointer to CustomControl
/// </summary>
private CustomControl Control
{
get
{
return (CustonControl)base.Owner;
}
}
}
在计算机中,安装了Visual Studio和其他计算机,在那里安装了测试代理,我用代码启动了testmethod:
AutomationPattern[] supportedPatterns = customControl.GetSupportedPatterns();
foreach (var supPattern in supportedPatterns)
Trace.WriteLine(supPattern.ProgrammaticName);
跟踪结果:
在带有visual studio的计算机中:
QTAgent32.exe, <a class=success>Playback - {43} [SUCCESS] MouseButtonClick - "[UIA]ControlType='RadioButton' && AutomationId='allCriteriaRadioButton'"
\0</a>
**ValuePatternIdentifiers.Pattern;
GridPatternIdentifiers.Pattern**
QTAgent32.exe, IEDOM : StopSession of the plugin called before StartSession
QTAgent32.exe, UIA : StopSession of the plugin called before StartSession
在带有测试代理的计算机中:
QTAgent32.exe, <a class=success>Playback - {43} [SUCCESS] MouseButtonClick - "[UIA]ControlType='RadioButton' && AutomationId='allCriteriaRadioButton'"
\0</a>
**GridPatternIdentifiers.Pattern**
QTAgent32.exe, IEDOM : StopSession of the plugin called before StartSession
QTAgent32.exe, UIA : StopSession of the plugin called before StartSession
为什么我在第二种情况下只得到IGridProvider?