2010-04-21 41 views
1

我評價一個UI自動化UI測試,我有以下按鈕WPF應用程序定義:UI自動化按鈕樣式啓用

<Button Style="{DynamicResource ButtonStyle}" x:Name="MyBtn"/> 

,當我需要在視覺上禁用按鈕我只是改變風格所以用戶知道該按鈕被禁用(顏色改變),但仍然在內部啓用按鈕,所以我仍然可以啓動OnClick事件,以便在用戶點擊「禁用」按鈕時顯示消息。

現在的問題是,我不知道如何從UI Automation檢查它當前應用的樣式,即如果該按鈕被禁用或啓用。你知道我該怎麼做?

在正常情況下,我應該做這樣的事情:

Automation.Condition cEBtn = new PropertyCondition(AutomationElement.AutomationIdProperty, "MyBtn"); 

AutomationElement mybtnElement = appRegraceElement.FindFirst(TreeScope.Children, cEBtn); 

bool disMyBtn = (bool)mybtnElement .GetCurrentPropertyValue(AutomationElement.IsEnabledProperty); 

但在我的情況下,按鈕始終處於啓用狀態,因此我需要檢查應用到按鈕的樣式。

非常感謝。

問候

回答

1

在這個環節上的評論說: http://social.msdn.microsoft.com/Forums/en/windowsaccessibilityandautomation/thread/129d2ea6-91ae-4f65-b07e-c36684ae742b

WPF屬性不能(還)暴露自動化特性。儘管如此,邁克爾提出了一種解決方法。我會把它留在這裏以防萬一對某人有用。

<Style TargetType="Button"> 
    <Setter Property="AutomationProperties.ItemStatus" 
     Value="{Binding RelativeSource={RelativeSource Self}, Path=Style}" /> 
</Style> 

,你可以看到我們在這裏做的是揭露(所有按鈕)使用自動化財產ItemStatus WPF屬性風格。那麼這個風格可以從UI自動化客戶端一樣,可以得到:

Automation.Condition cEBtn = new PropertyCondition(AutomationElement.AutomationIdProperty, "MyBtn"); 
AutomationElement mybtnElement = appRegraceElement.FindFirst(TreeScope.Children, cEBtn); 
string a = (string)mybtnElement.GetCurrentPropertyValue(AutomationElement.ItemStatusProperty); 

作爲一種解決方法的確定對我來說,但它有兩個問題,它要求我更新的應用程序代碼,不應該是在測試過程中必須的,而且它一次只能暴露一個屬性。

此致敬禮, Víctor