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.
After digging a bit into this issue, I found a semi-solution. I looked at how the UIMap
designer files generate their code for a ListView
(I adjusted the code a bit for my own variables):
var itemscontrol = new WpfList(window);
itemscontrol.SearchProperties[WpfList.PropertyNames.AutomationId] = "CustomersItemsControl";
itemscontrol.WindowTitles.Add("MainWindow");
var count = itemscontrol.Items.Count(); // Returns the correct value!
I copied this code and it seems to work for an ItemsControl
as well, at least some properties do, such as WpfList.Items
. So, it's a partial solution I guess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With