We are unable to automate testing for our WPF application using MS Coded UI test. The sample application contains a RadGridView with just two columns. In one column, we have added a button which displays a Message Box on click. We are trying to automate this button click.
The grid is defined like this:
<telerik:RadGridView x:Name="MyLinkGrid" Height="135" AutoGenerateColumns="False" Margin="10" Width="300">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn x:Name="GridViewDataColumnID" Header="ID" DataMemberBinding="{Binding Name}" />
<telerik:GridViewColumn x:Name="GridViewDataColumnName" Header="Name" IsReadOnly="True">
<telerik:GridViewColumn.CellStyle>
<Style TargetType="telerik:GridViewCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Button x:Name="colID" Content="{Binding ID}" VerticalContentAlignment="Center" Foreground="Blue" Click="Button_Click" Width="Auto" AutomationProperties.AutomationId="{Binding ID}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</telerik:GridViewColumn.CellStyle>
</telerik:GridViewColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button_Click");
}
During playback the button click event is not automated.
However if we move the ID column after the Name column, the button click event is played back and message box is displayed.
Attached is the sample WPF app along with the Coded UI test project.
Also if we add DataTemplate to our column definition, the button click event doesn’t occur during playback.