开发者

How do I get ItemStatus from a UITestControl?

The UI Automation framework has a base class, AutomationElement, that has a property开发者_Go百科, 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.


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)));
        }
    }

    ...
}

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;
}

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜