I created a small WPF application (just to explore how Coded UI Testing works). My application contained an ItemsControl
, but the Coded UI Test Builder UIMap could not find the appropriate control.
XAML:
<ItemsControl ItemsSource="{Binding Path=Customers, Mode=OneTime}"
AutomationProperties.AutomationId="CustomersItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock AutomationProperties.AutomationId="{Binding Path=Id, StringFormat='Customer_{0}', Mode=OneWay}"
Margin="5">
<TextBlock.Text>
<MultiBinding StringFormat="{}{1}, {0}">
<Binding Path="FirstName" />
<Binding Path="LastName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
The problem that I have is that even though WPF has an ItemsControlAutomationPeer
, the Coded UI Test Builder cannot locate the control to be added to the UIMap. The only way I got around it was by getting the root AutomationElement, then utilizing the TreeWalker.ControlViewWalker
(I used the code found in this answer), however that solution doesn't give me access to the control itself, just the AutomationElement
. Ideally, since there is an AutomationPeer for the control, I was wondering if there was a better way to get at this control (even if it is impossible to get to for the UIMap).
Also, a side note. I understand already that Visual Studio ignores TextBlock
s when doing Coded UI Testing because there can be so many produced. Right now I'm more concerned with getting to the ItemsControl
itself, not the individual TextBlock
s that are generated from within it.