How do I get ItemStatus from a UITestControl?

自作多情 提交于 2019-12-22 13:57:00

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1849001/how-do-i-get-itemstatus-from-a-uitestcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!