Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 212: ListViewRow can't be created with DictionaryMappedItemFactory #214

Merged
merged 2 commits into from
Feb 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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