How do you get the Microsoft Coded UI Test Builder to recognize an ItemsControl?

I created a small WPF application (just to find out how Coded UI Testing works). My application contained ItemsControl , but UIMap Coding UI Test Builder could not find the corresponding 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 is that even if WPF has ItemsControlAutomationPeer , the Coded Test Builder cannot find the control added to the UIMap. The only way I got TreeWalker.ControlViewWalker to get root AutomationElement and then use TreeWalker.ControlViewWalker (I used the code found in this answer ), however this solution don’t give me access to the control itself, just AutomationElement . Ideally, since for The control has AutomationPeer, I was wondering if there is a better way to get this control (even if it is not possible for UIMap).


Also side notes. I already realized that Visual Studio ignores TextBlock when doing Coded UI Testing, because there can be so many released. Now I'm more worried about getting to the ItemsControl itself, and not from the individual TextBlock created from it.

+6
source share
2 answers

After delving into this problem, I found a half-solution. I looked at how the UIMap constructor UIMap generate their code for the ListView (I slightly adjusted the code 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 ItemsControl , at least some properties like WpfList.Items , so this is a partial solution that I assume.

+4
source

ItemsControl and TextBlock do not contain AutomationPeer. ItemsControlAutomationPeer is an abstract class. Here's one solution for finding items, not the ItemsControl item itself: WPF ItemsControl with TestStack White .

0
source

All Articles