TestStack / White

DEPRECATED - no longer actively maintained
Other
1.02k stars 486 forks source link

ListView doesn't count redundant values #265

Open hash615 opened 10 years ago

hash615 commented 10 years ago

TestStack.White nuget version 13.3

We got a ListView in a WPF-application with two identical entries. When we want to check the count of the ListView the returned value is one. If we use two different values it works fine.

WPF-XAML:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="ListViewBugTestCase.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <x:Array x:Key="strings" Type="sys:String" 
            xmlns:sys="clr-namespace:System;assembly=mscorlib">
            <sys:String>2</sys:String>
            <sys:String>2</sys:String>
        </x:Array>
    </Window.Resources>
    <StackPanel>
        <ListView ItemsSource="{Binding Mode=OneWay, Source={StaticResource strings}}" Name="list">
            <ListView.View>
                <GridView>
                    <GridViewColumn/>
                </GridView>
            </ListView.View>
        </ListView>
        <Label Content="{Binding ElementName=list, Path=Items.Count}"></Label>
    </StackPanel>
</Window>

Testcase:

[Test]
public void ListViewTest()
{
    var window1 = app.GetWindow("MainWindow", InitializeOption.NoCache);
    var label = window1.Get<Label>();
    var listView = window1.Get<ListView>();
    var count = listView.Items.Count;
    Assert.AreEqual(2, int.Parse(label.Text)); // Succeeds, has a binding on the real ListView.Items.Count
    Assert.AreEqual(2, count); // Fails
}
maxinfet commented 9 years ago

I looked into this issue and even inspect shows the same problem. I went ahead and opened a ticket with microsoft for this since even inspect has the issue and after debugging the issue we are only getting one element back from AutomationElement.FindAll. Here is the link to the Microsoft ticket https://connect.microsoft.com/VisualStudio/feedback/details/1309895/listview-not-reporting-correct-count-when-using-uiautomation.