Make sure Codeduitest is able to identify element inside a Hidden TabItem

Recently there was a customer who reported an issue (Details https://social.msdn.microsoft.com/Forums/en-US/vsautotest/thread/e977a27a-bb67-4919-af84-1d06ce891047/).

In his application there was a TabItem who's Visibility property was set to Collapsed. Due to this AutomationElement.FromPoint (UIA api) was not able to return correct element(inside the hidden tabitem) from point (and hence codeduitest test was not able to recognize element from point). This looks like some optimization which WPF UIA implementation has when drilling down for element from point.

The workaround is to override the default TabItemAutomationPeer implementation and override few properties so that the drilling works fine. Attached is the custom TabItem class which I wrote to make this possible. You just need to use the TabItemCustom class instead of default TabItem class to achieve this. TabItemCustomPeer is the automationpeer implementation of TabItemCustom. TabItemCustomPeer is the important class which made this possible.

TabItemCustom (2).cs

Comments

  • Anonymous
    April 09, 2015
    Hi there Siddharta, I am facing this problem and even using your class CUIT is not working because even though teh controls inside the tabitem are visible there is node in the hierarchy tree, the tabitem, which is hidden because collapsed. Am I doing anything wrong? BR, Marco        <TabControl x:Name="TabControlGlobal" Grid.Row="1" Margin="8" BorderThickness="1" SelectionChanged="TabControlGlobal_SelectionChanged">            <TabControl.ItemContainerStyle>            </TabControl.ItemContainerStyle>            <local:TabItemCustom x:Name="FirstTabItem" Header="{DynamicResource MyDialog_UserTabItem}">                <local:TabItemCustom.Content>                    <Grid>                        <Grid.RowDefinitions>                            <RowDefinition Height="200"/>                        </Grid.RowDefinitions>                        <TabControl x:Name="tabControlUser" Grid.Row="0"/>                    </Grid>                </local:TabItemCustom.Content>            </local:TabItemCustom>            <local:TabItemCustom x:Name="SecondTabItem" Header="{DynamicResource MyDialog_LocalTabItem}">                <local:TabItemCustom.Content>                    <Grid>                        <Grid.RowDefinitions>                            <RowDefinition Height="200"/>                        </Grid.RowDefinitions>                        <TabControl x:Name="tabControl" Grid.Row="0"/>                    </Grid>                </local:TabItemCustom.Content>            </local:TabItemCustom>        </TabControl>