2

UI Automated フレームワークでいくつかのカスタム コントロールをテストしようとしています。私のコントロールの 1 つは TextBox の基本クラスを持ち、もう 1 つは Control を継承しています。テストで最初のコントロールを見つけることができますが、TreeScope とプロパティ条件をどのように組み合わせても、ウィンドウ内で 2 番目のカスタム コントロールを見つけることができません。

次のように、XAML でカスタム コントロールを宣言します。

<Grid>
    <test:CustomTextBox Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="customTextBox1" VerticalAlignment="Top" Width="120" />
    <test:CustomUserControl Height="25" HorizontalAlignment="Left" Margin="12,62,0,0" Name="customUserControl1" VerticalAlignment="Top" Width="119" />
</Grid>

以下のようなサンプルテストがあります。

[Test]
public void TestUsingValuePattern()
{
    // Getting RootElement...
    AutomationElement rootElement = AutomationElement.RootElement;
    Assert.IsNotNull(rootElement);

    // Searching for Test Window...
    AutomationElement windowElement = rootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "TestWindow"));
    Assert.IsNotNull(windowElement);

    // Searching for Custom TextBox control...
    AutomationElement customElement1 = windowElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "customTextBox1"));
    Assert.IsNotNull(customElement1);

    // Searching for Custom User control
    AutomationElement customElement2 = windowElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "customUserControl1"));
    Assert.IsNotNull(customElement2);
}

2 番目のアサーションは常に null を返すため、テストの実行を開始することさえできません。この問題を解決するために私ができることについて何か提案はありますか?

4

2 に答える 2

0

以下のスレッドのチェックを参照してください。コントロールを使用して要素を取得するには、各コントロールに AutomationId を使用する必要があります。

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b0892b5c-3850-4518-8063-d4eb5a8d9781/

于 2012-12-25T11:08:20.597 に答える