diff --git a/src/TestStack.White.UITests/ControlTests/ListControls/ListViewTest.cs b/src/TestStack.White.UITests/ControlTests/ListControls/ListViewTest.cs index 58434f95..4308651a 100644 --- a/src/TestStack.White.UITests/ControlTests/ListControls/ListViewTest.cs +++ b/src/TestStack.White.UITests/ControlTests/ListControls/ListViewTest.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using TestStack.White.Factory; using TestStack.White.UIItems; using TestStack.White.UIItems.ListViewItems; using Xunit; @@ -20,6 +21,7 @@ protected override void ExecuteTestRun(WindowsFramework framework) RunTest(SelectedRow); RunTest(SelectedRows); RunTest(SelectWhenHorizontalScrollIsPresent); + RunTest(CreateListViewRowDirectlyFromAutomationElement); } void SelectRow() @@ -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"); + var factory = new DictionaryMappedItemFactory(); + var ae = listView.Rows[1].AutomationElement; + var uiItem = factory.Create(ae, listView.ActionListener); + Assert.IsAssignableFrom(uiItem); + } + } void SelectedRow() { using (var window = StartScenario("OpenListView", "ListViewWindow")) diff --git a/src/TestStack.White/UIItems/ListViewItems/ListViewHeader.cs b/src/TestStack.White/UIItems/ListViewItems/ListViewHeader.cs index 61d6fced..ef1d22f9 100644 --- a/src/TestStack.White/UIItems/ListViewItems/ListViewHeader.cs +++ b/src/TestStack.White/UIItems/ListViewItems/ListViewHeader.cs @@ -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); } } } \ No newline at end of file diff --git a/src/TestStack.White/UIItems/ListViewRow.cs b/src/TestStack.White/UIItems/ListViewRow.cs index d4357a51..33f7a966 100644 --- a/src/TestStack.White/UIItems/ListViewRow.cs +++ b/src/TestStack.White/UIItems/ListViewRow.cs @@ -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; @@ -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)