Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top