Domanda

Il href="http://msdn.microsoft.com/en-us/library/ms747327.aspx" rel="nofollow noreferrer"> quadro ha una classe base, AutomationElement , che ha una proprietà, ItemStatus , che può essere utilizzato per memorizzare stringhe arbitrarie. Sto cercando di ottenere che proprietà dal Visual Studio 2010 I test codificati dell'interfaccia utente classe base, UITestControl .

È stato utile?

Soluzione

Guarda le recensioni prove codificati dell'interfaccia utente generato codice per WpfControl. Ha una proprietà, NativeElement. Questa proprietà è un AutomationElement.

public abstract class WpfControl : UITestControl
{
    ...

    public virtual object NativeElement
    {
        get
        {
            return ((object)(this.GetProperty(UITestControlProperties.Common.NativeElement)));
        }
    }

    ...
}

È possibile scrivere un metodo di estensione per lanciare e ottenere ItemStatus.

public static string GetItemStatus(this WpfControl control)
{
    var automationElement = (AutomationElement)control.NativeElement;
    return automationElement.Current.ItemStatus;
}

Non sono certo il motivo per cui NativeElement viene registrato come un object (che rende il cast ridondante getter). NativeElement Tutti i controlli WPF sono di tipo AutomationElement. Vorrei suggerire la modifica del codice generato e semplicemente chiamando direttamente control.NativeElement.Current.ItemStatus.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top