我想測試一些自定義控件與UI自動化框架。我的一個控件有一個TextBox的基類,另一個從Control繼承。我能找到我跟我的測試第一控制,但是不管我用什麼樣的組合TreeScope和財產狀況,我無法找到該窗口中我的第二個自定義控制。的FindFirst始終返回null AutomationElement
我聲明在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);
}
第二個斷言總是返回null,所以我甚至不能開始在它上面運行測試。這裏有什麼建議,我可以做什麼來解決這個問題?