Skip to content

Commit

Permalink
Merge pull request #214 from ivan-danilov/fix-212
Browse files Browse the repository at this point in the history
Fix 212: ListViewRow can't be created with DictionaryMappedItemFactory
  • Loading branch information
JakeGinnivan committed Feb 9, 2014
2 parents cdc3f07 + 101d8b1 commit 292762d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using TestStack.White.Factory;
using TestStack.White.UIItems;
using TestStack.White.UIItems.ListViewItems;
using Xunit;
Expand All @@ -20,6 +21,7 @@ protected override void ExecuteTestRun(WindowsFramework framework)
RunTest(SelectedRow);
RunTest(SelectedRows);
RunTest(SelectWhenHorizontalScrollIsPresent);
RunTest(CreateListViewRowDirectlyFromAutomationElement);
}

void SelectRow()
Expand All @@ -45,6 +47,17 @@ void SelectScrolledRow()
Assert.Equal("App15", listView.SelectedRows[0].Cells["Value"].Text);
}
}
void CreateListViewRowDirectlyFromAutomationElement()
{
using (var window = StartScenario("OpenListView", "ListViewWindow"))
{
var listView = window.Get<ListView>("ListView");
var factory = new DictionaryMappedItemFactory();
var ae = listView.Rows[1].AutomationElement;
var uiItem = factory.Create(ae, listView.ActionListener);
Assert.IsAssignableFrom<ListViewRow>(uiItem);
}
}
void SelectedRow()
{
using (var window = StartScenario("OpenListView", "ListViewWindow"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public virtual ListViewColumns Columns

public virtual ListViewColumn Column(string text)
{
return Columns.Find(delegate(ListViewColumn column) { return column.Text.Equals(text); });
return Columns.Find(column => column.Text == text);
}
}
}
21 changes: 21 additions & 0 deletions src/TestStack.White/UIItems/ListViewRow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Windows.Automation;
using TestStack.White.AutomationElementSearch;
using TestStack.White.Factory;
using TestStack.White.UIItems.Actions;
using TestStack.White.UIItems.ListViewItems;
using TestStack.White.WindowsAPI;
Expand All @@ -12,6 +13,26 @@ public class ListViewRow : UIItem
private readonly ListViewHeader header;
private readonly AutomationElementFinder finder;
protected ListViewRow() {}

public ListViewRow(AutomationElement automationElement, ActionListener actionListener)
:this(automationElement, actionListener, GetHeader(automationElement, actionListener))
{
// we need this ctor because we want to be able to create rows from DictionaryMappedItemFactory
// without separate factory
}

// Creates new header for specified row AutomationElement (use only when no Header is available)
private static ListViewHeader GetHeader(AutomationElement automationElement, ActionListener actionListener)
{
var parentGrid = TreeWalker.ControlViewWalker.GetParent(automationElement);
if (parentGrid == null)
throw new UIItemSearchException("Can't find parent DataGrid element");
if (parentGrid.Current.ControlType != ControlType.DataGrid)
throw new UIItemSearchException("Parent of specified element is not DataGrid");
var parentGridFinder = new AutomationElementFinder(parentGrid);
var factory = new ListViewFactory(parentGridFinder, actionListener);
return factory.Header;
}

public ListViewRow(AutomationElement automationElement, ActionListener actionListener, ListViewHeader header)
: base(automationElement, actionListener)
Expand Down

0 comments on commit 292762d

Please sign in to comment.