TestStack / White

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

Get .IsSelected of a WPF DataGridCelll (ListViewCell) #353

Open JohanLarsson opened 8 years ago

JohanLarsson commented 8 years ago

Hello, I have the need for testing if a cell is selected in a DataGrid but can't think of a way to do it. Discussion about it here

maxinfet commented 8 years ago

I moved this here from the discussion in gitter so its easier for me to find.

So after doing some investigation into checking if a cell is selected I found that our implementation of ListViewCell is a limiting factoring in implementing this.

ListViewCell inherits from Label so the collection of cells is really just a collection of labels that do not have access to the cell automation element. When I inspected the automation element for the ListViewCell it was actually the text of the cell.

Unfortunately this means it's a larger fix then me just wiring up some events. Not really sure how I would add this into the existing API. I would appreciate anyones feed back on how to maintain the existing API while exposing a IsSelected on a cell in ListView.

I think the right fix is to have the ListViewCell hold its own automationid and then have it hold a UIItem that can then be cast back to Label, Combobox or Checkbox (These are the 3 controls support in the Cells property of ListViewRow).

I didnt check TableCell (The winform equivalent to ListViewCell) but just from glancing at it, it inherits from UIItem which means this will more than likely be possible to implement since I should have access to the cell automation element instead of its contents automation element.

Also one more note, the tests for DataGridTests are alittle odd since we have two different classes that are responsible for implementing winforms and wpf. Winforms uses Tables and WPF uses ListView and the way we keep these test in the same file is just checking our framework and then Assert.Ignore if its the wrong framework. To me it seems like we should split these out into two different sets of tests. One set of test for Tables and one set of tests for ListView.

maxinfet commented 8 years ago

After looking at this ListView code and taking one failing attempt at getting this to work I have a feeling I should decouple ListView and DataGrid. Currently making changes to ListView to support this functionality will break the ListView control. I could make this work as the code stands but I am pretty sure it would introduce far to many special cases.