diff --git a/src/TestStack.White/Factory/TableRowFactory.cs b/src/TestStack.White/Factory/TableRowFactory.cs index 59eb5bb6..ab2b98dd 100644 --- a/src/TestStack.White/Factory/TableRowFactory.cs +++ b/src/TestStack.White/Factory/TableRowFactory.cs @@ -1,8 +1,6 @@ -using System; using System.Collections.Generic; using System.Windows.Automation; using TestStack.White.AutomationElementSearch; -using TestStack.White.Configuration; using TestStack.White.UIItems.Actions; using TestStack.White.UIItems.TableItems; @@ -10,42 +8,52 @@ namespace TestStack.White.Factory { public class TableRowFactory { - private readonly AutomationElementFinder automationElementFinder; - private static readonly Predicate RowPredicate; - private static int result; + private readonly AutomationElementFinder automationElementFinder; - static TableRowFactory() + public TableRowFactory(AutomationElementFinder automationElementFinder) { - RowPredicate = - element => - element.Current.Name.Split(' ').Length == 2 && - // row header containes no Numbers - (int.TryParse(element.Current.Name.Split(' ')[0], out result) || - int.TryParse(element.Current.Name.Split(' ')[1], out result)); + this.automationElementFinder = automationElementFinder; } - public TableRowFactory(AutomationElementFinder automationElementFinder) + public virtual int NumberOfRows { - this.automationElementFinder = automationElementFinder; + get { return GetRowElements().Count; } } public virtual TableRows CreateRows(IActionListener actionListener, TableHeader tableHeader) { - List rowElements = GetRowElements(); + var rowElements = GetRowElements(); return new TableRows(rowElements, actionListener, tableHeader, new TableCellFactory(automationElementFinder.AutomationElement, actionListener)); } private List GetRowElements() { // this will find only first level children of out element - rows - List descendants = automationElementFinder.Children(AutomationSearchCondition.ByControlType(ControlType.Custom)); - var automationElements = new List(descendants.FindAll(RowPredicate)); + var descendants = automationElementFinder.Children(AutomationSearchCondition.ByControlType(ControlType.Custom)); + var automationElements = new List(descendants.FindAll(IsRow)); return automationElements; } - public virtual int NumberOfRows + private static bool IsRow(AutomationElement element) { - get { return GetRowElements().Count; } + var parts = element.Current.Name.Split(' '); + + if (parts.Length < 2) + { + return false; + } + + int result; + + for (var i = parts.Length - 1; i >= 0; i--) + { + if (int.TryParse(parts[i], out result)) + { + return true; + } + } + + return false; } } -} \ No newline at end of file +}